您的位置:首页 > 数据库 > Oracle

Oracle 主键id 实现自增长

2019-09-21 13:11 1711 查看
版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。 本文链接:https://blog.csdn.net/wendy_qgh/article/details/101104121
  1. 创建序列
create sequence t_student_seq
minvalue 1
nomaxvalue
start with 1
increment by 1
nocycle
nocache;

说明:
创建索引

create sequence t_student_seq —索引名称
minvalue 1 –最小值
nomaxvalue –不设置最大值
start with 1 –从1开始计数
increment by 1 –每次加1个
nocycle –一直累加,不循环
nocache; –不建缓冲区

  1. 创建触发器:
create trigger t_student_trigger
before insert on student
for each row
begin
select t_student_seq.nextval into :new.id from dual;
end;

说明:
create trigger (t_student_trigger)----触发器名称
before insert on (student)— 表名
for each row–行级触发
begin
select t_student_seq.nextval into :new.id from dual;
end;

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: