I have a encountered strange behaviour adding columns to an existing table. I run those scripts using osql several instances.
a_table have initially three columns
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
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!