db2 自动增长列从论坛里查询得到以下结果:
1.生成列和标识列
对于自增字段,可以通过两种方式指定:
generated by default as identity
generated always as identity
区别是,第一种方式在插入数据时允许手工指定自增字段的值,只要不重复即可,并且数据库会自动设置下一个值;第二种方式则不允许指定,只能由数据库自动分配并插入。
IDENTITY列可生成用作主键的递增序列号。
create table jj(j int generated by default as identity,jj int) 这种方式当指定插入default时,j字段为自增1.2........
create table jjj(j int generated always as identity ,jj int )这种方式只能指定插入default,如果指定j的值将会出错.
2.
create sequence num_seq
start with 1 increment by 1 nomaxvalue nocycle
insert into sale values(nextval for num_seq,.....)
3.
create sequence seq_test
as bigint
start with 1
increment by 1
minvalue 10000
maxvalue
99999999999999999
cycle
cache 20
order;
values nextval for seq_test;
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/12913851/viewspace-621064/
,如需转载,请注明出处,否则将追究法律责任。