SQL Server/T-SQL Tutorial/System Settings/DB ID
Returning the Current Database ID and Name
4> SELECT DB_ID() DatabaseID, DB_NAME() DatabaseNM
5> GO
DatabaseID DatabaseNM
---------- -------------------------------------------------------------------------------------------------------------
-------------------
1 master
(1 rows affected)