Alternative code to achieve the TRY-Catch functionality

  • Please comment on how to query a alternative code to achieve the TRY-Catch functionality in SQL Server.

    Also, what are the disadvantages of foreign key constraints in SQL Server.

  • Please comment on how to query a alternative code to achieve the TRY-Catch functionality in SQL Server.

    I don't know any functionality that really replaces the try-catch. If an exception occurs within a try-block, it is not acutally raised, except you do it explicitly (for example in the catch-block).

    Getting the text of the error message is not possible too as far as I know, the error_message() function only works within the catch-block.

    For error handling, you can query the variable @@error and use if-statements to continue a code block or not.

    Also, what are the disadvantages of foreign key constraints in SQL Server.

    Performance! Any insert in a table has to do a lookup on all by foreign keys referenced tables to check whether the inserted key exists in the referenced tables. Of course this needs time.

    These lookups can also lead to deadlocks in special situations.

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply