DECLARE @dbname varchar( 128 )
SELECT @dbname = 'tempdb' -- test
-- In SQL6x/70/2000
IF DB_ID( @dbname ) IS NOT NULL
PRINT 'DB Exists...'
ELSE
PRINT 'DB does not exist...'
-- In SQL70/2000
IF EXISTS( SELECT * FROM INFORMATION_SCHEMA.SCHEMATA
WHERE CATALOG_NAME = @dbname )
PRINT 'DB Exists...'
ELSE
PRINT 'DB does not exist...'
IF DATABASEPROPERTY( @dbname , 'IsOffline' ) IS NOT NULL
PRINT 'DB Exists...'
ELSE
PRINT 'DB does not exist...'