sql server - Continue inserting data in tables skipping duplicate data issue -
set xact_abort off; begin tran declare @error int declare @sql nvarchar(max) set @sql=n''; select @sql=some select query fetch insert scripts begin try exec sp_executesql @sql commit end try begin catch select @error=@@error if @error=2627 begin continue inserting data end if @error<>2627 begin rollback end end catch i unable continue inserting data when duplicate data comes. there alternative way continue running sql queries irrespective of duplicate data? don not want alter index or table. i unable continue inserting data when duplicate data comes. there alternative way continue running sql queries irrespective of duplicate data. dont want alter index or table. what can change insert scripts call them, in pseudo statement: select @sql=some select query fetch insert scripts change generation script: instead of generating insert ... values(...) statements, generate if not exists(...) insert ... values(...) statem...