There is no way to do this that will not slow down your process, but here is one way that will facilitate it. You can add a trigger instead to this table for insertions and updates. The trigger checks each entry before inserting it and ensures that it does not cause a primary key violation. You can even create a second table to detect violations and have a different primary key (for example, an identification field) on this, and the trigger will insert rows into your table with errors.
Here is an example of how a trigger can work:
CREATE TRIGGER mytrigger ON sometable INSTEAD OF INSERT AS BEGIN INSERT INTO sometable SELECT * FROM inserted WHERE ISNUMERIC(somefield) = 1 FROM inserted; INSERT INTO sometableRejects SELECT * FROM inserted WHERE ISNUMERIC(somefield) = 0 FROM inserted; END
In this example, I check the field to make sure it is numeric before inserting data into the table. You will need to modify this code to check for primary key violations, for example, you can join the INSERTED table in your existing table and only insert rows in which you cannot find a match.
source share