加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

oracle实现自增长

发布时间:2020-12-12 14:41:37 所属栏目:百科 来源:网络整理
导读:1.建表 create table test( id number(20) NOT NULL primary key,/*主键,自动增加,注意主键为number型*/ 2.建自动增长序列 Create Sequence addAuto_Sequence Increment by 1 -- 每次加几个 start with 1 -- 从1开始计数 nomaxvalue -- 不设置最大值,设置

1.建表

create table test( id number(20) NOT NULL primary key,/*主键,自动增加,注意主键为number型*/

2.建自动增长序列

Create Sequence addAuto_Sequence
Increment by 1 -- 每次加几个
start with 1 -- 从1开始计数
nomaxvalue -- 不设置最大值,设置最大值:maxvalue 9999
nocycle -- 一直累加,不循环
cache 10;

3.建触发器

Create trigger addAuto before insert on test(表名) for each row /*对每一行都检测是否触发*/

begin select addAuto_Sequence.nextval into:New.id from dual; end;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读