I’m working on versioning our database and am now searching for a way to drop all stored procedures and functions from a C# Console Application. I’d rather not create a stored procedure that drops all stored procedures and functions. It has to be some sql executed from C#.
I tried to drop the stored procedure before creating it, but I got this message:
System.Data.SqlClient.SqlException:
‘CREATE/ALTER PROCEDURE’ must be the
first statement in a query batch.
Script for one SP for example:
DROP PROCEDURE [dbo].[sp_Economatic_LoadJournalEntryFeedbackByData]
SET ANSI_NULLS ON
SET QUOTED_IDENTIFIER ON
CREATE PROCEDURE [dbo].[sp_Economatic_LoadJournalEntryFeedbackByData]
@Data VARCHAR(MAX)
AS
BEGIN
...
END
So I guess before creating all SP’s and functions I’ll need to drop all SP’s and functions first with one sql script.
You can check for existence before dropping:
… then create it…
I would add this for each stored procedure you want to create.