Do you have a comment or suggestion to improve SQL Server? We’d love to hear it!

"GO" in 2nd half of nested block comments breaks batch parsing in SSMS and SQLCMD

If a "GO" batch separator is embedded in the second half of nested block comments (i.e. anywhere after the first "*/" and before the final "*/" ),
the batch parsing breaks in both SSMS and SQLCMD. While embedded blocks comments are accepted by SQL Server, the batch parsing
(just the part that splits a script into multiple batches) of both of these clients (and possibly also SMO) does not truly accept nested block
comments and assumes that the block comment has ended upon seeing the first "*/". ALSO, the position of the initial "/*" makes a difference
in that if the "/" of the start of the block comment is the first character on the line (position 1) then the errors will happen, but if there are
one or more spaces or tabs before the "/", then the parser works correctly. Meaning:

Works: /* GO first /* middle */ last */
Works: /* first /* GO middle */ last */
ERROR: /* first /* middle */ GO last */
Works: /* first /* middle1 */ /* GO middle2 */ last */
Works: /* first /* middle1 */ /* middle2 */ GO last */
ERROR: /* first /* middle1 *//* middle2 */ GO last */

There are 3 additional cases shown in the SQL scripts attached to this ticket that cannot be expressed on a single line like the variations shown above.

For what it's worth, OSQL does not have this bug, but had another which errors on embedded batch separators if they were the first thing on the line.

2 votes
Sign in
Check!
(thinking…)
Reset
or sign in with
  • facebook
  • google
    Password icon
    Signed in as (Sign out)

    We’ll send you updates on this idea

    AdminMicrosoft SQL Server (Admin, Microsoft Azure) shared this idea  ·   ·  Flag idea as inappropriate…  ·  Admin →

    1 comment

    Sign in
    Check!
    (thinking…)
    Reset
    or sign in with
    • facebook
    • google
      Password icon
      Signed in as (Sign out)
      Submitting...

      Feedback and Knowledge Base