My simple question is, can I put Create/Alter Table, Procedure, Column, Views, etc statements inside Transaction? What I mean is this? Will the below statements be valid?
BEGIN TRANSACTION [Tran1]
BEGIN TRY
--CREATE ALTER Table Procedure
--CREATE ALTER Table Procedure
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION [Tran1];
DECLARE @ErrorNumber nchar(5), @ErrorMessage nvarchar(2048);
SELECT
@ErrorNumber = RIGHT('00000' + ERROR_NUMBER(), 5),
@ErrorMessage = @ErrorNumber + ' ' + ERROR_MESSAGE();
RAISERROR (@ErrorMessage, 16, 1);
END CATCH
As far as I am aware DDL sentences can be transactional while in read-committed isolation mode (pessimistic), which is the default mode.
msdn Link