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

Oracle建表,建主键,自增

时间:2015-07-30 18:59:18      阅读:129      评论:0      收藏:0      [点我收藏+]

标签:

Oracle建表,建主键,自增

--建表

create table Test(

id number(4) not null primary key,

name varchar2(25)

)

--序列

create sequence Test_sequence

increment by 1--每次增加几个

start with 1  --从1开始计数

minvalue 1

nomaxvalue    --不设置最大值

nocycle       --一直累加,不循环

nocache       --不建缓冲区

--触发器

create trigger Test_tiger before

insert on Test for each row when(new.id is null)

begin

  select Test_sequence.nextval into:new.id from dual;

  end;

--测试

insert into Test(name) values(‘zhangsan‘);

对已有的表中数据,对id进行自增设置

 

create sequence seq_a_id

minvalue 1

nomaxvalue 

start with 1

increment by 1

nocache;

update sys_menu_dict set MENU_ID = seq_a_id.nextval

Oracle建表,建主键,自增

标签:

原文地址:http://www.cnblogs.com/ls-Aimee/p/4689982.html

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