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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to find out database name in stored proc

Status
Not open for further replies.

millerk

Programmer
Jul 5, 2002
133
US
I am going to have an agent that is running a stored procedure every 24 hours. This will be run on several different databases. Under certain conditions this proc will be sending an email to alert our admin of problems. I need to be able to specify in the email and in our error log which instance of SQL Server and what database name it came from.

I've got the server name and instance part with SERVERPROPERTY('servername')
but I couldn't find a way to get the current database name and I don't want to hardcode it since I would have to change it for every database we put this on.
Is there a function or an @@ that will tell me this?

Thanks,
Shanti
 
Nevermind, i found it.

DB_NAME()

I should have guessed it. lol.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top