I have a SQL Server transaction which adds a column to a table, and then it adds some value to that column. It runs perfectly, but it doesn't commit the changes.
I checked with @@trancount
, and it's value is 1 after running the query.
What is wrong with the transaction?
Thanks!
BEGIN TRANSACTION
ALTER TABLE Table
ADD ColumnName VARCHAR(200) NULL;
GO
BEGIN TRY
UPDATE ColumnName
SET ColumnName = 'some value'
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION;
END CATCH;