Most runtime errors don’t rollback transaction

Most runtime errors don’t rollback transaction

Many developers mistakenly believe that any error inside a transaction will make the transaction fail and automatically rollback. However, this is true only for fatal errors, such as most errors with severity equal to 16 or higher. The commonest runtime error – for example duplicate primary keys, violation of unique constraints and foreign key relationship – aren’t fatal and therefore won’t rollback the transaction.

To rollback a transaction when an error occurs you must manually check each statement for runtime error using the @@ERROR global variable, as in the following code snippet:


See also  How College Students Can Shape the Future of Tech Responsibility

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist