December 31, 2011

Check database exists or not in SQL

T-SQL

IF EXISTS(SELECT * FROM sys.databases WHERE name = 'DBName')
BEGIN
      PRINT 'Database Exists.'
END
ELSE
BEGIN

      PRINT 'Database does not exist.'
END

That’s It.
Enjoy Learning.

No comments:

Post a Comment