Oracle、MySQL、SQL Server自增變量的方法
SQL Server自增變量和Oracle等數據庫中的實現方法都不盡相同,下面就為您詳細介紹三種常用數據庫自增變量的方法,希望對您能有所幫助。
1、MySQL的自增變量是比較好記的,使用AUTO_INCREMENT關鍵字,如果知道英文的就容易記憶了,如下創建一個帶有自增變理的表:
create table test(id int AUTO_INCREMENT
primary key not null,name varchar(50));
注釋:此處的id一定要申明為主鍵,否則會報錯。
2、SQl Server使用identity關鍵字實現SQL Server自增變量,可以很容易指定從什么數開始,增幅是多少,SQL Server自增變量的方法如下:
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');
【編輯推薦】