如何進(jìn)行DB2 和SQL Server自增列比較,相信很多沒有經(jīng)驗(yàn)的人對(duì)此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個(gè)問題。
成都創(chuàng)新互聯(lián)是專業(yè)的西充網(wǎng)站建設(shè)公司,西充接單;提供成都網(wǎng)站制作、網(wǎng)站建設(shè),網(wǎng)頁設(shè)計(jì),網(wǎng)站設(shè)計(jì),建網(wǎng)站,PHP網(wǎng)站建設(shè)等專業(yè)做網(wǎng)站服務(wù);采用PHP框架,可快速的進(jìn)行西充網(wǎng)站開發(fā)網(wǎng)頁制作和功能擴(kuò)展;專業(yè)做搜索引擎喜愛的網(wǎng)站,專業(yè)的做網(wǎng)站團(tuán)隊(duì),希望更多企業(yè)前來合作!
最近由于對(duì)SQL Server的自增列理解不夠好,導(dǎo)致了一個(gè)設(shè)計(jì)問題,做了2個(gè)小例子解釋一下
SQL Server的自增列
create table identitytest(
id int identity(1,1),
name varchar(20)
)
go
set IDENTITY_INSERT identitytest ON
go
insert into identitytest(id,name)values(1,'test1')
go
insert into identitytest(id,name)values(2,'test2')
go
set IDENTITY_INSERT identitytest OFF
go
insert into identitytest(name)values('test3')
go
set IDENTITY_INSERT identitytest ON
go
insert into identitytest(id,name)values(10000,'test4')
go
set IDENTITY_INSERT identitytest OFF
go
insert into identitytest(name)values('test5')
go
id name
1 test1
2 test2
3 test3
10000 test4
10001 test5
(5 rows affected)
1>
SQL Server的自增列的值取決于表里面的此列的當(dāng)前的最大值。
create table identitytest(
id bigint not null generated by default as identity (start with 1,increment by 1),
name varchar(20)
);
insert into identitytest(id,name)values(1,'test1');
insert into identitytest(id,name)values(2,'test2');
insert into identitytest(name)values('test3');
insert into identitytest(id,name)values(10000,'test4');
insert into identitytest(name)values('test5');
db2 => select * from identitytest;
ID NAME
-------------------- --------------------
1 test1
2 test2
1 test3
10000 test4
2 test5
5 record(s) selected.
db2 =>
DB2的自增列,當(dāng)你手工插入自增列的值的時(shí)候,DB2會(huì)無視你插入的值,DB2用自增列的定義產(chǎn)生值。
看完上述內(nèi)容,你們掌握如何進(jìn)行DB2 和SQL Server自增列比較的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,感謝各位的閱讀!