Technical Article

Check existence of a database

,

Create the Procedure

Compile the procedure

Run the procedure: -

EXEC usp_checkdb @dbname = 'Enter DB'

CREATE procedure usp_checkdb (@dbname nvarchar(128))
as
begin
/* Check, How to Run:

EXEC usp_checkdb @dbname = 'Enter DB'

*/
IF (EXISTS (SELECT name FROM master.dbo.sysdatabases 
WHERE ('[' + name + ']' = @dbname 
OR name = @dbname)))

SELECT 'YES'


IF (NOT EXISTS (SELECT name FROM master.dbo.sysdatabases 
WHERE ('[' + name + ']' = @dbname 
OR name = @dbname)))

SELECT 'No'
END

Rate

2.36 (11)

You rated this post out of 5. Change rating

Share

Share

Rate

2.36 (11)

You rated this post out of 5. Change rating