In the below query I want to catch the constraint errors and in the same time I want do not want to abort the transaction .
But the below query is aborting the transaction once a single constraint error comes in.
When I use the xact_abort off without try block the transaction is not aborting
create table test_const
(
name varchar(300),
id int primary key
)
create table erro_log
(
error nvarchar(max),
error_desc nvarchar(max),
)
set xact_abort off
begin try
insert into test_const select 'FRO',1
insert into test_const select 'FRO',1
insert into test_const select 'FRO',4
insert into test_const select 'FRO',5
end try
begin catch
declare @error varchar(500)
select @error = @@error
INSERT INTO erro_log
(
Error,
Error_desc
)
VALUES (
@error
,error_message()
)
end catch
select * from erro_log
select * from test_const