Database Version Control SQL Server 2008 Drop SP's and Functions

Posted by Lieven Cardoen on Stack Overflow See other posts from Stack Overflow or by Lieven Cardoen
Published on 2009-08-12T13:52:11Z Indexed on 2010/04/02 2:23 UTC
Read the original article Hit count: 433

I'm working on versioning our database and 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. I has to be some sql executed from C#.

I tried to drop the stored procedure before creating it, but I get 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.

© Stack Overflow or respective owner

Related posts about database

Related posts about version-control