"GO" used in a stored procedure

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave

    #1

    "GO" used in a stored procedure

    I have a stored procedure in sql 2000 that requires steps to be fully
    completed before moving to the next command in the procedure. I have
    tried to place the word "GO" after each statement. When I create the
    procedure then take a look at it through em, it only shows the code up
    until the word "GO".

    Example:
    CREATE PROCEDURE mytest
    as
    create table mytable col1 varchar(5), col2 varchar(10)
    GO
    insert into mytable (col1, col2) values(abc, def)

    All i see is:
    CREATE PROCEDURE mytest
    as
    create table mytable col1 varchar(5), col2 varchar(10)
    GO


    I need to be 100% certain that the table has already been created
    before trying to add records to it.

    Is there any command that makes t-sql halt until the previous command
    has finished?

    Thanks,
    Dave
  • David Portas

    #2
    Re: "GO&quo t; used in a stored procedure

    GO isn't a TSQL command. It marks the end of a batch in Query Analyzer and
    therefore signals the end of a stored procedure definition in that batch, so
    it cannot be part of an SP.

    --
    David Portas
    SQL Server MVP
    --


    Comment

    • Zach Wells

      #3
      Re: "GO&quo t; used in a stored procedure

      Dave wrote:
      [color=blue]
      > I have a stored procedure in sql 2000 that requires steps to be fully
      > completed before moving to the next command in the procedure. I have
      > tried to place the word "GO" after each statement. When I create the
      > procedure then take a look at it through em, it only shows the code up
      > until the word "GO".
      >
      > Example:
      > CREATE PROCEDURE mytest
      > as
      > create table mytable col1 varchar(5), col2 varchar(10)
      > GO
      > insert into mytable (col1, col2) values(abc, def)
      >
      > All i see is:
      > CREATE PROCEDURE mytest
      > as
      > create table mytable col1 varchar(5), col2 varchar(10)
      > GO
      >
      >
      > I need to be 100% certain that the table has already been created
      > before trying to add records to it.
      >
      > Is there any command that makes t-sql halt until the previous command
      > has finished?
      >
      > Thanks,
      > Dave[/color]

      You can be assured that the table will be created before the insert
      statement is executed. Each command will be 100% finished and committed
      before moving on to the next statement (unless you using transactions).

      Zach

      Comment

      • Dave F

        #4
        Re: "GO&quo t; used in a stored procedure



        David,

        Thanks for responding so quickly. I did read in several places that the
        GO command does exactly what you have stated.

        However, I still need to find a way to make sure that my code is
        finished executing before moving to the next step within my stored
        procedure.

        The example I posted earlier was really dummied down from what I really
        need to do. We have some procs here that are over 600 lines of code, and
        most of them depend on the previous chunk of code to have completed
        before they execute.

        Any other ideas would be greatly appreciated.
        Thanks,
        Dave

        *** Sent via Developersdex http://www.developersdex.com ***
        Don't just participate in USENET...get rewarded for it!

        Comment

        • Zach Wells

          #5
          Re: "GO&quo t; used in a stored procedure

          Dave F wrote:
          [color=blue]
          >
          > David,
          >
          > Thanks for responding so quickly. I did read in several places that the
          > GO command does exactly what you have stated.
          >
          > However, I still need to find a way to make sure that my code is
          > finished executing before moving to the next step within my stored
          > procedure.
          >
          > The example I posted earlier was really dummied down from what I really
          > need to do. We have some procs here that are over 600 lines of code, and
          > most of them depend on the previous chunk of code to have completed
          > before they execute.
          >
          > Any other ideas would be greatly appreciated.
          > Thanks,
          > Dave
          >
          > *** Sent via Developersdex http://www.developersdex.com ***
          > Don't just participate in USENET...get rewarded for it![/color]

          Like I said, SQL will ALWAYS complete a command before moving on to the
          next one. What makes you think this doesn't already happen?

          Zach

          Comment

          • Erland Sommarskog

            #6
            Re: "GO&quo t; used in a stored procedure

            [posted and mailed, please reply in news]

            Dave (funkdm1@yahoo. com) writes:[color=blue]
            > Is there any command that makes t-sql halt until the previous command
            > has finished?[/color]

            To echo what Zach said: there is no command that causes T-SQL to continue
            with the next command, before the previous has completed. So you
            have no reason to worry.


            --
            Erland Sommarskog, SQL Server MVP, sommar@algonet. se

            Books Online for SQL Server SP3 at
            http://www.microsoft.com/sql/techinf...2000/books.asp

            Comment

            • mswida

              #7
              Re: "GO&quo t; used in a stored procedure

              This is a catch 22 situation.

              Do you really need to create a new table each time you execute the stored proc?
              If so, use temporary tables.

              Otherwise empty your existing table before you insert rows.

              Comment

              Working...