I need to write a logic in one of my stored procedure like below.
While inserting the records into main table if any records causes Primary Key or Foreign Key violations system should insert those error records into other table without raising any error or stopping the flow.
Main Table :
Validation Table :
This query executes successfully and 3 records inserted in data table.
This query fails and no records inserted in data table.
As per my requirement I need to write a code that, valid records inserted into data table and error causes or invalid records diverted or inserted into data_invalid table with out raising any error or stopping the flow.
Please give your inputs.
you need to use TRY...CATCH logic that will handle the error or the PK/FK violation and then carry out the process you need.
answered Jul 03 '12 at 07:46 AM