Metadata Functions (Transact-SQL)
Metadata functions return information about the database schema, objects, and system configuration. These functions are useful for querying information about your SQL Server environment directly from T-SQL.
Examples
Here's an example of how to get the name of a database given its ID:
SELECT DB_NAME(1); -- Returns the name of the master database
SELECT DB_NAME(DB_ID('AdventureWorks2019')); -- Returns the ID and then the name of the AdventureWorks2019 database
And an example of retrieving the definition of a stored procedure:
SELECT OBJECT_DEFINITION(OBJECT_ID('usp_GetCustomerInfo')); -- Returns the T-SQL code for the stored procedure