0

I created a number of scripts to be run separately but was asked to combine them all so the DBA only has to do it once. The problem is that I cannot seem to combine them to run together. Only the first item in the query gets run. How do I format these to run together in one big script?

   USE [DEV]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    Create PROCEDURE [dbo].[Projects]
       @ProjectID            int,
       @ClientID             int
    AS
    BEGIN
        .....Cool procedure here
    END
   GRANT EXECUTE ON [dbo].[Projects] TO Admin, Employee

INSERT INTO random_table(stuff)
VALUES (stuff)
2
  • if you put print 'test' before and after your insert is anything printed? Commented Jan 11, 2011 at 21:10
  • Check out my reply at the end! Commented Jan 11, 2011 at 21:16

4 Answers 4

4

Add a GO between statements

USE [DEV]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    Create PROCEDURE [dbo].[Projects]
       @ProjectID            int,
       @ClientID             int
    AS
    BEGIN
        .....Cool procedure here
    END

   GO -- Add GO here

   GRANT EXECUTE ON [dbo].[Projects] TO Admin, Employee

   GO -- Add GO here
INSERT INTO random_table(stuff)
VALUES (stuff)
Sign up to request clarification or add additional context in comments.

1 Comment

Works great. Adding Go was all that was needed. Thanks.
2
   USE [DEV]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    Create PROCEDURE [dbo].[Projects]
       @ProjectID            int,
       @ClientID             int
    AS
    BEGIN
        .....Cool procedure here
    END
   GRANT EXECUTE ON [dbo].[Projects] TO Admin, Employee
GO -- added this "go" statement
INSERT INTO random_table(stuff)
VALUES (stuff)

Comments

0

Insert GO after each statement.

Comments

0
USE [DEV]
    GO
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    Create PROCEDURE [dbo].[Projects]
       @ProjectID            int,
       @ClientID             int
    AS
    BEGIN
        .....Cool procedure here
    END
    GO //add Go after every statement
   GRANT EXECUTE ON [dbo].[Projects] TO Admin, Employee
   GO
   INSERT INTO random_table(stuff)
   VALUES (stuff)

Although, I would recommend you to generate script of Database schema (including Stored procedures, functions, table creation, insertion, updation and deletion) from your SQL server database and save it with .SQL file and you don't have to place these GOs manually. Take a look at this fine example

2 Comments

This is how I would prefer as well. I was just stuck manually combining some scripts and realized I had no idea how to do it. Thanks.
Mark it as answer, if you think it has helped yo :=)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.