Alex Rivera | Logout

How to query the name of the current SQL Server database instance?

Asked 2008-09-24T20:46:13.193
41

It is a bit of a "chicken or egg" kind of query, but can someone dreamup a query that can return the name of the current database instance in which the query executes? Believe me when I say I understand the paradox: why do you need to know the name of the database instance if you're already connected to execute the query? Auditing in a multi-database environment.

I've looked at all the @@ globals in Books Online. "SELECT @@servername" comes close, but I want the name of the database instance rather than the server.

Edit
Report

1 Answer

1

You should be able to use:

SELECT SERVERPROPERTY ('InstanceName') 
answered 2008-09-24T20:50:55.570

Your Answer