如何在MySQL&Oracle下創建自動遞增字段
在MySQL下創建自動遞增字段
create table article //先創建一個表
(
id int primary key auto_increment
title varchar(
);
insert into article values (null
select * from article; 結果如下
Id
Title
a
insert into article values (null
insert into article values (null
insert into article (title) values (
select * from article; 結果如下
Id
Title
a
b
c
d
但是oracle沒有這樣的功能
假設關鍵字段為id
create sequence seq_test_ids
minvalue
maxvalue
start with
increment by
nocache
order;
<!
<!
建解發器代碼為
create or replace trigger tri_test_id
before insert on test_table
for each row
declare
nextid number;
begin
IF :new
select seq_test_id
into nextid
from sys
:new
end if;
end tri_test_id;
OK
From:http://tw.wingwit.com/Article/program/Oracle/201311/18903.html