How to check if exists Stored Procedure in Sql Server

We can use the sys.procedures catalog view to check the existence of a stored proedure.
Here in the below script we are checking the existence of the stored procedure spAgent.

Example:
IF EXISTS(SELECT 1 FROM sys.procedures 
          WHERE Name = 'spAgent')
BEGIN
  PRINT Exists'
END
else
begin 
  PRINT 'Exists'
End
Result:

Post a Comment

0 Comments