It can sometimes be useful to know the id of a given database, e.g. for filtering events when profiling. Here are a few ways to do that:
-- Current database select db_id() -- Named database select db_id('Northwind') -- All databases use master select name, dbid from sysdatabases