How to Get the Current Database Name, Database ID in SQL Server

The DB_NAME() function returns the current database name. You can use this in the following way.
 

SELECT DB_NAME();

Get Database ID: The DB_ID() function returns the database ID for the given database name. You can use this in the following way.

Syntax : DB_ID([‘database name’]) 

Example:

SELECT DB_ID(DB_NAME());

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s