Quite often a simple things makes experienced DBA to look for simple thing. Here are few things which I used to get confused couple of years ago. Now I know it well and have no issue but recently I see one of the DBA getting confused when looking at the DBID from one of the DMV and not able to related that directly to Database Name.
-- Get Current DatabaseID SELECT DB_ID() DatabaseID; -- Get Current DatabaseName SELECT DB_NAME() DatabaseName; -- Get DatabaseName from DatabaseID SELECT DB_NAME(4) DatabaseName; -- Get DatabaseID from DatabaseName SELECT DB_ID('tempdb') DatabaseID; -- Get all DatabaseName and DBID SELECT name,database_id FROM sys.databases;
Reference: Pinal Dave (http://blog.SQLAuthority.com)