Tuesday, 27 February 2018

Microsoft SQL Transactions

Microsoft SQL Transactions

--A transaction that rolls back where there is an error
--Only batches that run successfully are commited.

begin transaction

begin try

insert into [test].[dbo].[options ftse]([product])
values('01/03/2018');

insert into [test].[dbo].[options ftse]([product])
values('#01/03/2018#lkjhgfddfgtghgfddfgghhhhgdrghhjujkuhgdrghhyhjjuygffrfgfggh');

commit transaction;

end try

begin catch

rollback transaction

print 'error, one or more batches did not commit.';

end catch;
--the second batch fails due to the column length being too short for the value.

Inline image 1

No comments:

Post a Comment