To get Database Name from Database ID run the following query (in this example Database ID is 2):
SELECT DB_NAME(2) AS Database_Name;
To get Database ID from Database Name run the following query (in this example Database Name is tempdb):
SELECT DB_ID('tempdb') AS Database_ID;
To get the list of all Database Names and Database IDs on the SQL Server instance:
SELECT name as Database_Name, database_id as Database_ID
FROM sys.databases;
If you want to see how to get the name or Database ID of the current Database in SQL Server, read related article:
Get the Name or ID of the current Database in SQL Server