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;

你可能感兴趣的:(orcale)