Line Termination

  • I've been going through some of the stored procedures that were created by the previous DBA to make sure I understand them. In some cases, he used a semi-colon at the end of a line of code, and sometimes nothing. Sometimes at the end of an End block, he placed a semi-colon and sometimes not.
     
    Is there some kind of criteria for a line terminator in T-SQL?
     
    em
  • Not that I know of.  I've never had to use 'em explicitly.  But it can be usefull to mark the end of something.  Anyone else got a better explaination?

  • Hi

     

    This might not be 100% right but as far as I know it go like this.

    ;           The semi colon is the ANSI standard to end a SQL statement and works in MS SQL.

     

    Go       This is just in MS SQL and does the same as the semi colon.

     

    BEGIN Are block that you would usually use with and if statement.

    END

                IF @Count > 1

                Begin

                            --Run some SQL

                End

                ELSE

                BEGIN

                            --Run something else

    END

     

     

     

    Mike

  • Ken Powers had a decent article abotu the differences of the two back in January...

    http://www.sqlservercentral.com/columnists/kpowers/thegocommandandthesemicolonterminator.asp

    Hope this helps clear up the difference.

    -Luke.

    To help us help you read this[/url]For better help with performance problems please read this[/url]

  • 'go' does quite a bit more than the semi-colon, for example, all variables declared before the go are no longer available after the go

  • Thank you, that article was perfect.
     
    em

Viewing 6 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply