tags:

views:

94

answers:

4

Are SQL Server database Ids always positive?

As in the dbid from sysdatabases.

SELECT name, dbid 
  FROM master.dbo.sysdatabases

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

+4  A: 

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.

Erich
+3  A: 

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.

Nissan Fan
A: 

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

Brandon
+3  A: 

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

Dave