5

One of the developers in my company had set up a sql profiler with a filter on the database id.

He is telling me that the database id that he is looking for has changed.

The database in question is still there, but instead of 61 it is now 60.

enter image description here

Marcello Miorelli
  • 17,274
  • 53
  • 180
  • 320

1 Answers1

9

sys.databases.database_id is not assigned like an identity. Rather the lowest positive integer available will be used. Repro is pretty simple:

create database a;
create database x;
create database b;

drop database x;

select * from sys.databases where database_id > 4;

sys.databases shows a gap in the database_id sequence

In the event you drop and re-create b, the database_id will decrement by 1.

drop database b;
go
create database b;

sys.databases showing database_id for database b decremented from previous screencap

As for the profiler question - you should probably ask a separate question and include the trace definition at a minimum. Dropping a database while there's a live profiler trace does not create the error you describe.

Peter Vandivier
  • 5,485
  • 1
  • 25
  • 49