Is it possible anyhow to raise system exception on catching exception manually?-Collection of common programming errors

You can’t raise system errors. RAISERROR(2627…) is illegal. Beside the fact that you’re lying (no error 2627 occurred), you’re missing the inserts into the message format.

Application should never rely on IDENTITY continuity, the fact that you complain that it ‘increases the autoincrement’ revels your application has a bug (in design for sure, if not in code). IDENTITY values may contain gaps, is part of their specifications.

As to what is better, to insert and catch, or to try to update: it depends on your prevalent pattern. If the value is likely to exist, the UPDATE first strategy is better. If the value is likely not to exist or if the probability is unknown it is better to INSERT and catch the error, for reasons of performance and, more importantly, correctness (SELECT check is never correct under concurrency).

Originally posted 2013-11-09 23:12:06.