In SQL Server, when should you use GO and when should you use semi-colon ;?

后端 未结 5 1796
南方客
南方客 2020-12-04 10:51

I’ve always been confused with when I should use the GO keyword after commands and whether a semi-colon is required at the end of commands. What is the differences and why/w

5条回答
  •  自闭症患者
    2020-12-04 11:19

    GO

    Go is a batch separator. This means that everything in that batch is local to that particular batch.

    Any declarations of Variables, Table Variables, etc do not go across GO statements.

    #Temp tables are local to a connection, so they span across GO statements.

    Semicolon

    A Semicolon is a statement terminator. This is purely used to identify that a particular statement has ended.

    In most cases, the statement syntax itself is enough to determine the end of a statement.

    CTE's however, demand that the WITH is the first statement so you need a semicolon before the WITH.

提交回复
热议问题