Oracle设置主键自增
Oracle设置主键自增Oracle中没有自增字段,可通过序列+触发器间接实现,cmd中sqlplus登录,直接运行即可。一般要经过一下几步:1建立数据表Codecreate table Test_Increase(userid number(10) primary key, /*主键,自动增加*/username varchar2(20));2创建自动增长序列CREATE SEQUENCE TestIncrease_SequenceINCREMENT BY 1 -- 每次加几个START WITH 1 -- 从1开始计数NOMAXVALUE -- 不设置最大值NOCYCLE -- 一直累加,不循环CACHE 10;3创建触发器CREATE TRIGGER Test_Increase BEFOREinsert ON Test_Increase FOR EACH ROWbeginselect TestIncrease_Sequence.nextval into:New.userid from dual;end;