Posted on 2008-08-10 15:26
freedoom 閱讀(164)
評論(0) 編輯 收藏 所屬分類:
JAVA技術(好文保存)
Oracle,SQL Server,MySQL的自增變量設置:
1、MySQL的自增變量是比較好記的,使用AUTO_INCREMENT關鍵字,如果知道英文的就容易記憶了,如下創建一個帶有自增變理的表:
create table test(id int AUTO_INCREMENT
primary key not null,name varchar(50));
注釋:此處的id一定要申明為主鍵,否則會報錯。
2、SQl Server使用identity關鍵字,可以很容易指定從什么數開始,增幅是多少,如下:
create table test(id int identity(100,10)
primary key not null,name varchar(50));
3、Oracle不能夠在創建表的時候指定自動關鍵字,它需要重新創建sequence,然后以"創建鍵。nextval"來引用:
create table test(id int primary key
not null,name varchar(50));
create sequence test_id(最好是表名+序列號標記)
increment by 1 start with 1 maxvalue 9999;
引用如下:
insert into test(test_id.nextval,'www');