Monday, March 19, 2012

How can you get the current database name via T-SQL?

I have stored some commonly used sprocs and user-defined functions I have created in a separate db.

Some of these functions work with the current db sysobjects table, for instance, and need to "know" the database that I am calling the sproc/function from.

Is there anyway to return the current database name via T-SQL to assign to a local variable which I can then include in the procedure/function execute statement?

Bill

Use the system function: db_name().

SELECT db_name()

|||

Code Snippet

select db_name()

|||

Thanks so much. I knew is was probably simple, just couldn;t find it in the T-SQL help.

No comments:

Post a Comment