Two of the metadata functions available in SQL Server include DB_NAME()
and ORIGINAL_DB_NAME()
. Both functions are similar in that they return the name of a database. But they are also different. You definitely don’t want to confuse the two, as they serve different purposes.
In a nutshell, each function works as follows:
DB_NAME()
returns the name of a specified database. If you don’t explicitly specify a database, it returns the current database.ORIGINAL_DB_NAME()
returns the database name specified by the user in the database connection string.