DECLARE @dbname nvarchar(128)
SET @dbname = N'ourdbname'
IF (EXISTS (SELECT name FROM master.dbo.sysdatabases
WHERE ('[' + name + ']' = @dbname OR name = @dbname)))
PRINT 'db exists'
else
PRINT 'db not exists'
if db_id('ourdbname') is not null
print 'found'
else
print 'not found'