Friday, June 10, 2022

Stored procedure for database exist in SQL Server

 create proc [dbo].[CheckDbExist](@dbname varchar(500))

as

IF EXISTS (SELECT name FROM master.sys.databases WHERE name = @dbname)

select 'true'

else

raiserror('Database does not exist',16,1);

No comments:

Post a Comment