How do I check if a stored procedure exists in SQL Azure?
-
21-09-2019 - |
Question
I normally use the following code in SQL Server:
IF EXISTS (SELECT * FROM sysobjects WHERE id = OBJECT_ID(N'[dbo].[proc_MyProc]') AND OBJECTPROPERTY(id,N'IsProcedure') = 1)
DROP PROCEDURE [dbo].[proc_MyProc]
GO
How do I do this in SQL Azure? I get an error message: "Invalid object name 'sysobjects'."
Added:
The error was in fact in the checking if the stored procedure existed and have found code to do this:
IF EXISTS (SELECT Routine_Name from information_schema.Routines WHERE Routine_Name = 'proc_MyProc')
DROP PROCEDURE [proc_MyProc]
GO
Solution
I have updated the question and provided the answer.
OTHER TIPS
This also works in SQL Azure
if object_id('[dbo].[proc_MyProc]') is not null
DROP PROCEDURE [proc_MyProc]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow