T-SQL: Check if database exists

by Joe Hunter 15. March 2010 17:23

To check if a database exists, use the DB_ID() function:

IF db_id('AdventureWorks') IS NOT NULL
Print 'Database Exists'
ELSE
Print 'Database Does Not Exists'

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen