Orcale自增长主键

create table comments
(
ID numeric(4) not null  primary key,
url varchar2(200) null,
title varchar2(100) null,
huitie varchar2(100) null,
participation varchar2(100) null,
type varchar2(200) null,
content CLOB  null,
replytime varchar2(200) null,
address varchar2(200) null,
IP varchar2(200) null
)

CREATE SEQUENCE com_sequence
INCREMENT BY 1 -- 每次加几个
START WITH 1 -- 从1开始计数
NOMAXVALUE -- 不设置最大值
NOCYCLE -- 一直累加,不循环
NOCACHE -- 不建缓冲区

CREATE TRIGGER trig_com BEFORE
INSERT ON comments FOR EACH ROW WHEN (new.id is null)
begin
select com_sequence.nextval into:new.id from dual;
end;

posted on 2011-11-17 20:34  雨渐渐  阅读(298)  评论(0编辑  收藏  举报

导航