user2125853
user2125853

Reputation: 1315

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.

Upvotes: 3

Views: 888

Answers (1)

Sayan Malakshinov
Sayan Malakshinov

Reputation: 8655

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.

Upvotes: 3

Related Questions