简体   繁体   English

如何创建自动增量ID列?

[英]How can I create auto incremental id column?

I created a table in HP's Vertica database. 我在HP的Vertica数据库中创建了一个表。 I want to create auto incremental column in Vertica. 我想在Vertica中创建自动增量列。

In MySQL it is already done , and in Oracle I created it by using sequence and trigger but how can I do it in HP Vertica? 在MySQL中它已经完成,在Oracle中我使用序列和触发器创建它,但我怎样才能在HP Vertica中完成它?

It's actually pretty simple just the syntax is a bit different since in Vertica AUTO_INCREMENT needs to be specified as the column type. 实际上非常简单,只是语法有点不同,因为在Vertica中需要将AUTO_INCREMENT指定为列类型。 Here's a quick example 这是一个简单的例子

user=> create table test (
user(>   id AUTO_INCREMENT,
user(>   foo VARCHAR(255)
user(> );

user=> insert into test (foo) values ('hello');
 OUTPUT
--------
      1
(1 row)

user=> insert into test (foo) values ('world');
 OUTPUT
--------
      1
(1 row)

user=> select * from test;
 id |  foo
----+-------
  1 | hello
  2 | world
(2 rows)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM