patternMinor
Database_Id for our database in sys.databases does not match that of DB_ID ( '<our database' )
Viewed 0 times
db_iddatabasesmatchdatabasesysfordoesthatdatabase_idnot
Problem
The Database ID in sysdatabases and sys.databases for our database is 4.
The function DB_ID ( '' ) returns 5 for our database.
Also any missing index data for our database in the table sys.dm_db_missing_index_details is assigned to database_id 5 also.
It seems to me that the sys.databases should have ID 5 and NOT 4. This is driving me bonkers and making it so sp_BlitzIndex does not work.
Does anyone know why my database id doesn't match between sys.databases, sys.dm_db_missing_index_details and DB_ID() on SQL Azure? Is it actually screwed up or does this just work different in SQL Azure?
The function DB_ID ( '' ) returns 5 for our database.
Also any missing index data for our database in the table sys.dm_db_missing_index_details is assigned to database_id 5 also.
It seems to me that the sys.databases should have ID 5 and NOT 4. This is driving me bonkers and making it so sp_BlitzIndex does not work.
Does anyone know why my database id doesn't match between sys.databases, sys.dm_db_missing_index_details and DB_ID() on SQL Azure? Is it actually screwed up or does this just work different in SQL Azure?
Solution
Azure SQL DB is different !
The
The
Best is to use
People have reported that here and here.
One shouldn't rely on database id / db_id builtin in azure as it changes whenever database moves to a different sql instance (because of the database failover). Use name instead of the id. Also please note that the db_id can potentially be different than in the sys.databases
The
database_id column from sys.databases (dont use sysdatabases <-- its deprecated) will remain the same for the database.The
DB_ID() is a function and the value will change if the Azure DB is failed over.Best is to use
name <-- database name column.People have reported that here and here.
One shouldn't rely on database id / db_id builtin in azure as it changes whenever database moves to a different sql instance (because of the database failover). Use name instead of the id. Also please note that the db_id can potentially be different than in the sys.databases
Context
StackExchange Database Administrators Q#138809, answer score: 7
Revisions (0)
No revisions yet.