How to check if exists Database in Sql Server

We can use the sys.sysdatabases catalog view to check the existence of a Database.
Here in the below script we are checking the existence of the Database Mduaccountsmas.

Example:
IF EXISTS(SELECT * FROM master.sys.sysdatabases 
          WHERE name='Mduaccountsmas')
BEGIN
  PRINT 'Exists'
END
else
begin 
  PRINT 'Exists'
End
Result:

Post a Comment

0 Comments