Can database Ids be negative in SQL Server?
I know that you can have a total 32767 (for both 32 bit and 64 bit) (Maximum Capacity SQL Server)
I know that the first few database Ids are reserved for master, model, msdb and tempdb and 32767 is the hidden system resource database.
I have never seen a negative database Id but I would like to confirm that it is not possible.
In short, they can be, but they almost never are.
In the master DB, the id column in the sysdatabases table is defined as an identity column with seed 1 and increment 1. That means that, by default, SQL Server will always assign a positive DBID for any database you create.
However, it is possible to change,you can specify negative seeds and increments for identity columns,so you can reset the identity column of the sysdatabases table to -1, -1 and the next database you create will have ID -1, then -2, etc. -1 is a perfectly valid 16-bit integer value and so the identity field should have no trouble. You may have an issue with SQL Server naively checking the number of DBs it manages by checking the max DBID. I would not expect MSS to make that check in such a stupid way, but stranger things have happened, and I’ve never seen an instance with more than a couple dozen DBs on it.