Hi There
I am trying to write a script that applies all changes to a database within a single transaction, eveything must be applied or not.
The issue i have is with the following:
BEGIN TRAN
INSERT INTO .....
UPDATE .....
ALTER TABLE A ADD COLUMN
INSERT INTO TABLE A VALUES ...
COMMIT
The issue i have is that the insert after the ALTER TABLE references the new column, which it says does nto exist, normally to get around this you should do a GO statement before the INSERT.
However if i insert a GO statement it breaks the script since it ends the batch so in essence all i am executing is:
BEGIN TRAN
INSERT INTO .....
UPDATE .....
ALTER TABLE A ADD COLUMN
GO
This is obviously incorrect since the syntax does not commit, also it breaks all the sql up into seprate transactions.
Same applies if i create a stored proc in the bacth, the sp must be the first statement in a sql batch and a GO must delimt the end of the sp create statement, but i cann make it 1 tarnsaction with GO's obviously.
Any ideas
Thanx