DB2 Identity

IDENTITY:标识列
 
说明:表中一个数字列,DB2为每个被插入表中的行生成一个唯一的数值
一个表最多一个标识列
 
生成方式:
always:        DB2生成,应用程序不能提供显示值,保证唯一
by default:  应用程序显示提供,当应用程序不提供DB2生成,不能保证唯一
 
创建表:
create table inventory (partno INTEGER GENERATED ALWAYS AS IDENTITY
          (START WITH 100 INCREMENT BY 1), description CHAR(20) )
 
语句结果
insert into inventory VALUES (DEFAULT,'door') 
insert into inventory (description) VALUES ('hinge') 
insert into inventory VALUES (200,'windor') 
insert into inventory (description) VALUES ('frame')
inserts 100,door
inserts 101,hinge
error
inserts 102,frame

Comments

Popular posts from this blog

Nginx Proxy & Load Balance & LNMP

Snort+barnyard2+Snorby CentOS 6.5_64 Installation

ORACLE Error