开发者

Are SQL Server Database Ids always positive?

开发者 https://www.devze.com 2022-12-20 04:35 出处:网络
Are SQL Server database Ids always positive? As in the dbid from sysdatabases. SELECT name, dbid FROM master.dbo.sysdata开发者_JAVA百科bases

Are SQL Server database Ids always positive?

As in the dbid from sysdatabases.

SELECT name, dbid 
  FROM master.dbo.sysdata开发者_JAVA百科bases

This question has nothing to do with identity columns or primary keys.


Edited, since you changed the question.

In this query: SELECT name, dbid from master.dbo.sysdatabases The value of dbid will ALWAYS be positive, since it is defined as a 1,1 identity.


They don't have to be, but the general practice is to make them. You can easily create a Primary Key that is an indentity with a negative Identity Increment. You would also not make it an identity and give it a negative value as well.


There is some software (Microsoft Dynamics) that will not allow negative keys on integer fields that are more than 2 bytes. Other that that, I see no reason to limit the identity column to positive numbers when the column is not used as an external identity. i.e. Customer ID


They don't necessarily have to be, but they usually are.

You might be interested to read this discussion on MSDN: Advantage/Disadvantages of Negative Identity Values

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号