oracle创建自增主键

--history分享:

创建表:
create table tuser(
 id number(11) not null,
 name varchar2(20) not null,
 password varchar2(20),
 birthday date,
constraint tuser_pk primary key (id)
);
创建序列:
create sequence increase_seq increment by 1 start with 1 nomaxvalue nocycle cache 10;
创建trigger:
create or replace trigger tuser_trigger
before insert on tuser for each row
begin
select increase_seq.nextval into :new.id from dual; 
end; 

根据使用的工具,可能需要增加“/”来执行PL/SQL块。
测试:
insert into tuser(name,password,birthday) values('wujay','123456',null);
commit;
select * from tuser;
        ID NAME                 PASSWORD             BIRTHDAY
---------- -------------------- -------------------- --------------
         1 wujay                123456
修改表:
 alter table tuser rename column id to pk_tuser;

IT之界浩瀚无边 只有持之恒心方可打开一窗 偷窥此中奥秘之一二 取之受益,亦珍而视之 学之留香,方不失风范 共勉 共进
原文地址:https://www.cnblogs.com/zhangmin1987/p/8804432.html