oracle 触发器实现主键自增

时间:2014-05-15 14:00:51   收藏:0   阅读:403
bubuko.com,布布扣
drop table book;   
--创建表      
create table book(       
   bookId varchar2(4) primary key,   
   name varchar2(20)         
);   
--创建序列      
create sequence book_seq start with 1 increment by 1;    
  
--创建触发器      
create or replace trigger book_trigger       
before insert on book       
for each row       
begin       
select book_seq.nextval into :new.bookId from dual;      
end ;   
--添加数据      
insert into book(name)  values (cc);    
insert into book(name)  values (dd);   
  
commit;  
 

查询数据:select * from book; 

查询
select * from user_objects ubs where ubs.OBJECT_TYPE=‘SEQUENCE‘; 
bubuko.com,布布扣

 

oracle 触发器实现主键自增,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!