7

The Database ID in sysdatabases and sys.databases for our database is 4.

The function DB_ID ( '<our database>' ) 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?

Allison H.
  • 73
  • 4

1 Answers1

8

Azure SQL DB is different !

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

Kin Shah
  • 62,545
  • 6
  • 124
  • 245