Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to compare DB2 and SQL Server auto-increment columns

2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report