Check if a SQL Server database exists or not (TSQL)

Here is a usefull TSQL Script for checking if a database exists :

— Check if the Database Exists
DECLARE @DatabaseCount AS int
SELECT @DatabaseCount=COUNT(*) FROM master.dbo.sysdatabases WHERE name=‘master’
SELECT @DatabaseCount AS [DatabaseCount]

Leave a Reply