码迷,mamicode.com
首页 > 数据库 > 详细

Oracle新建表字段,如何使字段自增

时间:2018-03-29 14:56:23      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:number   space   code   rom   row   create   values   next   建表   

oracle的自增需要依靠序列和触发器共同实现

比如 新建一张表 

create table test

(id int primary key,
name varchar2(10));
 
创建一个序列
create sequence test_seq increment by 1 start with 
minvalue 1 maxvalue 9999999999999 nocache 
order;
 
触发器实现
create or replace trigger test_trigger
before insert on test
for each 
row
begin
  select  test_seq.Nextval into:new.id from dual;
end;
 
然后插入数据
insert into test (namevalues (‘张三‘);

Oracle新建表字段,如何使字段自增

标签:number   space   code   rom   row   create   values   next   建表   

原文地址:https://www.cnblogs.com/yachao1120/p/8669309.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!