Find out the name of the current database

If I want to know the server, I can use: @@SERVERNAME

Is there an equivalent function to get the database / directory name.

I know that we can install it in a script using a statement USE, but what if it was not installed, and I wanted to request in sproc what db I used.

+4
source share
3 answers

db_name() will give you the name of the current database.

+9
source

db_name () will get the name of the database you are using. you can see the result with: select db_name()

+4
source

:

SELECT DB_NAME() AS DataBaseName

Per SQL

+3

Source: https://habr.com/ru/post/1656013/


All Articles