running many CREATE VIEW and GRANT SELECT statements in one execution

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP





.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;







up vote
1
down vote

favorite












Is there a way to run multiple CREATE VIEW commands and/or multiple GRANT SELECT commands by hitting F5 in SQL Server Management Studio? If so, how can I do this?







share|improve this question


















  • 1




    You just need the batch terminator, which in SSMS is GO unless you altered this default
    – scsimon
    Sep 4 at 20:05
















up vote
1
down vote

favorite












Is there a way to run multiple CREATE VIEW commands and/or multiple GRANT SELECT commands by hitting F5 in SQL Server Management Studio? If so, how can I do this?







share|improve this question


















  • 1




    You just need the batch terminator, which in SSMS is GO unless you altered this default
    – scsimon
    Sep 4 at 20:05












up vote
1
down vote

favorite









up vote
1
down vote

favorite











Is there a way to run multiple CREATE VIEW commands and/or multiple GRANT SELECT commands by hitting F5 in SQL Server Management Studio? If so, how can I do this?







share|improve this question














Is there a way to run multiple CREATE VIEW commands and/or multiple GRANT SELECT commands by hitting F5 in SQL Server Management Studio? If so, how can I do this?









share|improve this question













share|improve this question




share|improve this question








edited Sep 8 at 12:37









mathewb

6821420




6821420










asked Sep 4 at 19:48









MacGyver

94592548




94592548







  • 1




    You just need the batch terminator, which in SSMS is GO unless you altered this default
    – scsimon
    Sep 4 at 20:05












  • 1




    You just need the batch terminator, which in SSMS is GO unless you altered this default
    – scsimon
    Sep 4 at 20:05







1




1




You just need the batch terminator, which in SSMS is GO unless you altered this default
– scsimon
Sep 4 at 20:05




You just need the batch terminator, which in SSMS is GO unless you altered this default
– scsimon
Sep 4 at 20:05










2 Answers
2






active

oldest

votes

















up vote
4
down vote



accepted










Multiple CREATE VIEW statements can be executed together if you separate them with keyword 'GO'



CREATE VIEW vw_test1 AS SELECT name FROM dbo.test1;
GO
CREATE VIEW vw)test2 AS SELECT name FROM dbo.test2;
GO
GRANT SELECT ON vw_test....





share|improve this answer



























    up vote
    3
    down vote













    You can use dynamic SQL. Encapsulate your CREATE VIEW and/or GRANT SELECT statement in text.
    ex:



    DECLARE @Query NVARCHAR(50)
    SET @Query = 'CREATE VIEW ... '
    exec sp_executesql @Query


    You can do that for all the queries you need to run and then just press F5






    share|improve this answer




















      Your Answer







      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "182"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      convertImagesToLinks: false,
      noModals: false,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













       

      draft saved


      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f216718%2frunning-many-create-view-and-grant-select-statements-in-one-execution%23new-answer', 'question_page');

      );

      Post as a guest






























      2 Answers
      2






      active

      oldest

      votes








      2 Answers
      2






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      4
      down vote



      accepted










      Multiple CREATE VIEW statements can be executed together if you separate them with keyword 'GO'



      CREATE VIEW vw_test1 AS SELECT name FROM dbo.test1;
      GO
      CREATE VIEW vw)test2 AS SELECT name FROM dbo.test2;
      GO
      GRANT SELECT ON vw_test....





      share|improve this answer
























        up vote
        4
        down vote



        accepted










        Multiple CREATE VIEW statements can be executed together if you separate them with keyword 'GO'



        CREATE VIEW vw_test1 AS SELECT name FROM dbo.test1;
        GO
        CREATE VIEW vw)test2 AS SELECT name FROM dbo.test2;
        GO
        GRANT SELECT ON vw_test....





        share|improve this answer






















          up vote
          4
          down vote



          accepted







          up vote
          4
          down vote



          accepted






          Multiple CREATE VIEW statements can be executed together if you separate them with keyword 'GO'



          CREATE VIEW vw_test1 AS SELECT name FROM dbo.test1;
          GO
          CREATE VIEW vw)test2 AS SELECT name FROM dbo.test2;
          GO
          GRANT SELECT ON vw_test....





          share|improve this answer












          Multiple CREATE VIEW statements can be executed together if you separate them with keyword 'GO'



          CREATE VIEW vw_test1 AS SELECT name FROM dbo.test1;
          GO
          CREATE VIEW vw)test2 AS SELECT name FROM dbo.test2;
          GO
          GRANT SELECT ON vw_test....






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Sep 4 at 20:04









          Unkush

          1103




          1103






















              up vote
              3
              down vote













              You can use dynamic SQL. Encapsulate your CREATE VIEW and/or GRANT SELECT statement in text.
              ex:



              DECLARE @Query NVARCHAR(50)
              SET @Query = 'CREATE VIEW ... '
              exec sp_executesql @Query


              You can do that for all the queries you need to run and then just press F5






              share|improve this answer
























                up vote
                3
                down vote













                You can use dynamic SQL. Encapsulate your CREATE VIEW and/or GRANT SELECT statement in text.
                ex:



                DECLARE @Query NVARCHAR(50)
                SET @Query = 'CREATE VIEW ... '
                exec sp_executesql @Query


                You can do that for all the queries you need to run and then just press F5






                share|improve this answer






















                  up vote
                  3
                  down vote










                  up vote
                  3
                  down vote









                  You can use dynamic SQL. Encapsulate your CREATE VIEW and/or GRANT SELECT statement in text.
                  ex:



                  DECLARE @Query NVARCHAR(50)
                  SET @Query = 'CREATE VIEW ... '
                  exec sp_executesql @Query


                  You can do that for all the queries you need to run and then just press F5






                  share|improve this answer












                  You can use dynamic SQL. Encapsulate your CREATE VIEW and/or GRANT SELECT statement in text.
                  ex:



                  DECLARE @Query NVARCHAR(50)
                  SET @Query = 'CREATE VIEW ... '
                  exec sp_executesql @Query


                  You can do that for all the queries you need to run and then just press F5







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Sep 4 at 19:54









                  Danielle Paquette-Harvey

                  5381414




                  5381414



























                       

                      draft saved


                      draft discarded















































                       


                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fdba.stackexchange.com%2fquestions%2f216718%2frunning-many-create-view-and-grant-select-statements-in-one-execution%23new-answer', 'question_page');

                      );

                      Post as a guest













































































                      Comments

                      Popular posts from this blog

                      List of Gilmore Girls characters

                      What does second last employer means? [closed]

                      One-line joke