Get the App
SLTechnology News&Howtos  ›  Database  › 

How to compare DB2 and SQL Server auto-increment columns

Shulou Source: shulou.com Published: 2022-05-31 13:07:45 09月29日 Update

It is believed that many inexperienced people don't know what to do about how to compare DB2 and SQL Server. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.

Recently, due to the poor understanding of the self-increasing column of SQL Server, there is a design problem. Two small examples are given to explain it.

Self-increasing column of SQL Server

Create table identitytest (

Id int identity (1 dint 1)

Name varchar (20)

)

Go

Set IDENTITY_INSERT identitytest ON

Go

Insert into identitytest (id,name) values (1)

Go

Insert into identitytest (id,name) values (2meme 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)

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 >

The value of the self-incrementing column of SQL Server depends on the current maximum value of this column in the table. 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)

Insert into identitytest (id,name) values (2meme Test2')

Insert into identitytest (name) values ('test3')

Insert into identitytest (id,name) values (10000)

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 self-increment column, when you manually insert the value of the self-increment column, DB2 will ignore the value you insert, DB2 uses the definition of the self-increment column to generate values.

After reading the above, have you mastered how to compare DB2 and SQL Server self-adding columns? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!

Tags: Problems content methods more maximum helpless to this end not enough examples reasons depends on this manual skills time maximum this column articles experience industry Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno MariaDB Docker Linux macOS