FK Checks Suppose you have two (or more) tables with foreign key constraints. My
question is thus:
Is it better to check if the fk exists before you try to perform the
insert or let SQL do it for you?
On one hand, if you check yourself and the key does not exist you can
gracefully handle it (maybe exit out of method with error). If you let
SQL do it, the server will throw an error which cannot be suppressed.
On the performance side, you doing the check will incur a slight (VERY
slight) hit since SQL will ALSO check anyways. |