Get the Name or ID of the current Database in SQL Server

To get the name of the current database used while running the query:

SELECT DB_NAME() AS Database_Name

To get the current Database ID used while running the query:

SELECT DB_ID() AS Database_ID

Current Database ID in SQL server

To see how to get Database Name from Database ID and Database ID from Database Name in SQL Server read related article:
Get Database Name from Database ID and Database ID from Database Name in SQL Server

If the post helped you, please share it:
Pin It

Leave a Reply

You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">