创建触发器,以便为t_forum表生成主键 博客分类: oracle Oracle序列触发器主键自增
程序员文章站
2024-02-05 16:11:34
...
首先创建序列
建表
--创建触发器,以便为t_forum生成主键
create sequence seq_forum_id increment by 1 start with 1;
建表
create table t_forum ( forum_id int not null, forum_name varchar2(100) default '' not null, forum_desc varchar2(100) default NULL, constraint pk_t_forum primary key (forum_id) );
--创建触发器,以便为t_forum生成主键
create or replace trigger tri_forum_id before insert on t_forum for each row declare -- local variables here nextID int; begin select seq_forum_id.nextVal into nextID from dual; :new.forum_id:=nextID; end tri_forum_id; /