I'm trying to do an alter table to add a new column on a table, then I would like to do some update on the existing rows in the table to add a value to the recently new added column and finally do a select * to check that everything is ok and then make a rollback of the entire thing.
Something like
declare @transactionNameA varchar(20);
declare @transactionNameB varchar(20);
select @transactionNameA = 'TransactionA';
select @transactionNameB = 'TransactionB';
begin transaction @transactionNameA
alter table A add Column int;
begin transaction @transactionNameB
update A set Column = 1 where ID=1;
select * from A;
rollback transaction @transactionNameB;
rollback transaction @transactionNameA;
When I write that code I get an error saying the the column doesn't exist
What am I doing wrong? Thanks for your time and help.
'COLUMN'
, because that's a reserved keyword in SQL Server?