How to check if the SQL Server Database exists

To check if the SQL Server Database exists, run the following code:

IF EXISTS (SELECT name FROM master.sys.databases WHERE name = N'Database_Name')
PRINT 'Database exists'
ELSE
PRINT 'Database does not exists'

check_if_database_exists