Get the Name or ID of the current Database in SQL Server

To get the name of the current database used while running the query:

SELECT DB_NAME() AS Database_Name

To get the current Database ID used while running the query:

SELECT DB_ID() AS Database_ID

Current Database ID in SQL server

To see how to get Database Name from Database ID and Database ID from Database Name in SQL Server read related article:
Get Database Name from Database ID and Database ID from Database Name in SQL Server