Columns are added in wrong order I have a encountered strange behaviour adding columns to an existing table. I run those scripts using osql several instances.

Let Table a_table have initially three columns A_col, B_col and C_col.

To extend this table I use the following statements:

IF NOT EXISTS (SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS 
            WHERE COLUMN_NAME = N'D_col' AND TABLE_NAME = N'a_table')
BEGIN
ALTER TABLE [dbo].[a_table] ADD [D_col] int DEFAULT -1 NOT NULL
END


Up to now this script worked fine. I have a script adding two batches of columns (15 each) separated with a GO statement.

IF NOT ... -- col 1
...
END
:
:
IF NOT ... -- col 15
...
END
GO

IF NOT ... -- col 16
...
END
:
:
IF NOT ... -- col 30
...
END
GO


I expect the columns 1-15 to be added first and 16-30 second. But it happens from time to time that the second batch gets executed first so the columns appear in the wrong order (16-30, 1-15).

Any explanation for this behaviour is appreciated!
Finally we were able to sort it out: It was a GO in a block comment /* ... GO ... */.

We tested the code in SSMS were the GO is ignored (as it is in a block comment). osql does not ignore it! We had the two batches in this block comment in a previous update. The first was ignored. The second was executed because the GO in the comment broke the comment.

Thanks to @gbn, @JNK and @Brandon for their help!