转自:https://www.2cto.com/database/201705/636725.html
数据库设置主键自增">oracle数据库设置主键自增:
1 --创建表 2 create table blog( 3 id integer primary key, 4 title varchar2(200), 5 content varchar2(20000), 6 user_id varchar2(45), 7 pub_date date); 8 9 --创建sequence: 10 create sequence blog_id_sequence 11 increment by 1 12 start with 1 13 nomaxvalue 14 nocache; 15 16 --创建触发器: 17 create trigger blog_id_autoincrement before 18 insert on blog for each row 19 when (new.id is null) 20 begin 21 select blog_id_sequence.nextval into:new.id from dual; 22 end;