In SQL Server, you can use the DB_ID()
function to return the ID of the current database, or another specified database.
The way it works is, you pass the name of the database as an argument, and then the function will return the ID of that database. If you don’t pass a name it will return the ID of the current database.