- 论坛徽章:
- 0
|
DB2创建表:
create table abin17(
id int not null ,
createtime timestamp default current_timestamp not null,
firstname varchar(100) default null,
lastname varchar(100) default null,
constraint pk_abin17 primary key (id)
)
DB2创建序列Sequence:
create sequence seq_abin17_id
as integer
start with 1
increment by 1
minvalue 1
maxvalue 999999
cache 20
order;
DB2创建触发器Trigger:
--TRIG_ARTICLE_ADDARTICLEFOLDER
CREATE TRIGGER TRI_abin17
NO CASCADE BEFORE INSERT ON abin17
REFERENCING NEW AS articlef
FOR EACH ROW MODE DB2SQL
BEGIN ATOMIC
DECLARE temp_id double;
SET temp_id = NEXTVAL FOR SEQ_abin17_id;
SET articlef.id = temp_id;
END;
然后插入记录:
insert into ABIN17 (firstname,lastname)values ('abin','strong');
insert into ABIN17 (firstname,lastname)values ('abin','strong');
然后看看是否主键自增:
select * from abin17
呵呵,结果是自然自增了。
自己看下,我的博客地址是:http://hi.baidu.com/stevenjohn/b ... 0616d00b46e016.html |
|