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# lkjhgfddfgtghgfddfgghhhhgdrghh jujkuhgdrghhyhjjuygffrfgfggh') ;
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.

--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#
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.
No comments:
Post a Comment