-- auto-increment : 每次插入新記錄時,自動插入主鍵值
-- 1.在oracle中 ,用 sequence 來創建 auto-increment
create sequence seq_person minvalue 1 start with 1 increment by 1 cache 10;
insert into person(id,name) values(seq_person.nextval,'張三');
---上面的代碼創建名爲 seq_person 的序列對象,它以 1 起始且以 1 遞增。
---該對象緩存 10 個值以提高性能。
---CACHE 選項規定了爲了提高訪問速度要存儲多少個序列值。
--2.在sql server 數據庫中,用 identity 來創建 auto-increment
------- 默認地,IDENTITY 的開始值是 1,每條新記錄遞增 1
create table persons(
id int primary key identity,
name varchar(32) not null
);