Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Retrieving Database ID in TSQL

Status
Not open for further replies.

mikemcginty

Programmer
Joined
Jul 11, 2002
Messages
184
Location
AU
This may be simple but I just can't find the solution

How do I programmatically (via TSQL) retrieve the DBID of the SQL database I am currently connected to?

Regards

Mike

When you call out for help in the darkness, and you hear a voice in return, you're probably just talking to yourself again!
 
This will do the trick.
Code:
select dbid
from master.dbo.sysdatabases
where name = db_name()

Denny
MCSA (2003) / MCDBA (SQL 2000)

--Anything is possible. All it takes is a little research. (Me)

[noevil]
(My very old site)
 
Or just:

Code:
SELECT DB_ID()

--James
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top