Skip to content
Advertisement

Is a rollback necessary when insert of a single database record fails?

I am not too familiar with database transactions. I was wondering about a situation where a single record is being inserted into a database. Is a transaction necessary. If so, if the insert of the one record fails, is a rollback necessary?

I am asking this related to JDBC but is can be in a general database sense.

Advertisement

Answer

From the doc:

  1. Statement-Level Rollback

    Statement-Level Rollback If at any time during execution a SQL statement causes an error, all effects of the statement are rolled back. The effect of the rollback is as if that statement had never been run. This operation is a statement-level rollback.

  2. Statement-Level Atomicity

    Statement-Level Atomicity Oracle Database supports statement-level atomicity, which means that a SQL statement is an atomic unit of work and either completely succeeds or completely fails.

So, you don’t need to rollback if you execute just the only insert statement and it fails.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement