新聞中心
SQL Server自增變量和Oracle等數(shù)據(jù)庫中的實現(xiàn)方法都不盡相同,下面就為您詳細介紹三種常用數(shù)據(jù)庫自增變量的方法,希望對您能有所幫助。

創(chuàng)新互聯(lián)公司堅持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站設(shè)計、網(wǎng)站制作、外貿(mào)營銷網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的巴州網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
1、MySQL的自增變量是比較好記的,使用AUTO_INCREMENT關(guān)鍵字,如果知道英文的就容易記憶了,如下創(chuàng)建一個帶有自增變理的表:
create table test(id int AUTO_INCREMENT
primary key not null,name varchar(50));
注釋:此處的id一定要申明為主鍵,否則會報錯。
2、SQl Server使用identity關(guān)鍵字實現(xiàn)SQL Server自增變量,可以很容易指定從什么數(shù)開始,增幅是多少,SQL Server自增變量的方法如下:
create table test(id int identity(100,10)
primary key not null,name varchar(50));
3、Oracle不能夠在創(chuàng)建表的時候指定自動關(guān)鍵字,它需要重新創(chuàng)建sequence,然后以"創(chuàng)建鍵。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');
【編輯推薦】
詳解SQL Server全局變量
SQL Server創(chuàng)建視圖的語法
SQL Server視圖定義信息的查詢
SQL Server排序規(guī)則的應(yīng)用
帶您了解SQL Server標識列
當前名稱:Oracle、MySQL、SQLServer自增變量的方法
標題網(wǎng)址:http://m.5511xx.com/article/dhoihih.html


咨詢
建站咨詢
