您好,登錄后才能下訂單哦!
如何進行DB2 和SQL Server自增列比較,相信很多沒有經(jīng)驗的人對此束手無策,為此本文總結(jié)了問題出現(xiàn)的原因和解決方法,通過這篇文章希望你能解決這個問題。
最近由于對SQL Server的自增列理解不夠好,導(dǎo)致了一個設(shè)計問題,做了2個小例子解釋一下
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)你手工插入自增列的值的時候,DB2會無視你插入的值,DB2用自增列的定義產(chǎn)生值。
看完上述內(nèi)容,你們掌握如何進行DB2 和SQL Server自增列比較的方法了嗎?如果還想學(xué)到更多技能或想了解更多相關(guān)內(nèi)容,歡迎關(guān)注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關(guān)證據(jù),一經(jīng)查實,將立刻刪除涉嫌侵權(quán)內(nèi)容。