Adding an Exception Handler to a CURSOR FOR Loop.
Summary: in this tutorial, you will learn how to use the SQL Server cursor to process a result set, one row at a time. SQL works based on set e.g., SELECT statement returns a set of rows which is called a result set. However, sometimes, you may want to process a data set on a row by row basis. This is where cursors come into play.
So, in this case the syntax of the INSERT statement would be correct but the exception would raise when inserting the record. Hence, we will use TRY-CATCH block. In TRY block code is written, whereas in CATCH block the exception would be caught.