oracle实现主键自动增长
生活随笔
收集整理的這篇文章主要介紹了
oracle实现主键自动增长
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
-- 序列
create sequence email_file_index_seq ??
? ?increment by 1 -- 每次加幾個
? ?start with 1 -- 從1開始計數
? ?NOMAXvalue -- 不設置最大值
? ?NOCYCLE -- 一直累加,不循環
? ?nocache -- 不設置緩存
? ?
-- 觸發器
?create or replace trigger email_file_index_tri
?before insert on EMAIL_FILE for each row -- EMAIL_FILE 為對應insert 的表
?begin
?select email_file_index_seq.nextval into:new.ID from dual;-- 其中ID為 EMAIL_FILE的一個列,區分大小寫
?end;
?
-- 測試?
insert into EMAIL_FILE (PATH, NAME) values ('path', 'test')
create sequence email_file_index_seq ??
? ?increment by 1 -- 每次加幾個
? ?start with 1 -- 從1開始計數
? ?NOMAXvalue -- 不設置最大值
? ?NOCYCLE -- 一直累加,不循環
? ?nocache -- 不設置緩存
? ?
-- 觸發器
?create or replace trigger email_file_index_tri
?before insert on EMAIL_FILE for each row -- EMAIL_FILE 為對應insert 的表
?begin
?select email_file_index_seq.nextval into:new.ID from dual;-- 其中ID為 EMAIL_FILE的一個列,區分大小寫
?end;
?
-- 測試?
insert into EMAIL_FILE (PATH, NAME) values ('path', 'test')
總結
以上是生活随笔為你收集整理的oracle实现主键自动增长的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 缓存工具类MyCacheUtil
- 下一篇: (10) nginx 统计模块安装使用和