sql server - Is checking for primary key value before insert faster than using try-catch? -


Basically I have a table with two field primary key columns (member, message) and I have a stored procedure that inserts one. New line in that table.

Now I check that a line exists with PK and is not included, but I have already come into the situation when the row was inserted at the right time by a separate process, checking and inserting the actual Before, so I am thinking in an alternative way.

I do not want to use the transaction because of the performance, so I was thinking of holding INSERT and adding it in the investigation, if the line is already present, then the join will fail. But "catch" will be silent which is fine.

My question is - is it throwing an error and it is holding an expensive operation?

If you do not expect the failures too often, it is OK to handle it by exceptions.

Checking will be reduced every time DB perfomance which can affect the application perfomance ...

Comments