Published on: 14 Oct, 2019

How to check if stored procedure exists in SQL Server?

Tumblr Digg Google Plus

There is a case when you need to check if a stored procedure in SQL Server exists. Especially if you build an application that requires some upgrade. There is a time you need to replace the existing stored procedure with the new one.

Below is the SQL query to check if the existing stored procedure and delete the existing stored procedure.

IF EXISTS (SELECT * from dbo.sysobjects WHERE Id = object_id(N'dbo.MyStoredProcedureName') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
	DROP PROCEDURE dbo.MyStoredProcedureName

Once it has been deleted, you can delete it again. Alternatively, if you prefer not to delete it, you can use the option to update by using the keyword ALTER.


There are no comments available.

Write Comment
0 characters entered. Maximum characters allowed are 1000 characters.