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.
if you are populating a code object from a database record, the object will initialize with an "ID" property of 0. Then if the populating is successful it will be something other than the default of 0.
Every table (except for the rare conditions) should have a PRIMARY KEY , that is a value or a set of values that uniquely identify a row. See here for discussion why. IDENTITY is a property of a column in SQL Server which means that the column will be filled automatically with incrementing values.
An identity column is a column (also known as a field) in a database table that is made up of values generated by the database. This is much like an AutoNumber field in Microsoft Access or a sequence in Oracle.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With