首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > 其他数据库 >

在Oracle中设立自动增长列

2012-09-04 
在Oracle中设置自动增长列【实现步骤】 1. 创建表blog_info, 具有ID和title两个字段, 其中ID将设置为自动增

在Oracle中设置自动增长列
【实现步骤】

1. 创建表blog_info, 具有ID和title两个字段, 其中ID将设置为自动增长列;

2. 创建序列:

  

 create sequence sq_blog_info    start with 1    increment by 1    nomaxvalue    nocycle    cache 10;

3. 创建触发器:

   
create or replace trigger tg_blog_info       before insert on blog_info for each row    begin       select sq_blog_info.nextval into :NEW.id from dual; --★注意: 此处的;是必须的    end;

4. 测试:

   
insert into blog_info (title) values('a');

热点排行