DML & Transactions questions and answers

INSERT, UPDATE, DELETE, COMMIT, ROLLBACK and ACID. Practise dml & transactions questions from the sql section of placement tests, with a worked explanation after every answer. Practice is free and needs no sign-up.

Sample dml & transactions questions with worked answers

Question 1

Which statement ends a transaction and makes all of its changes permanent?

  1. COMMIT
  2. ROLLBACK
  3. SAVEPOINT
  4. BEGIN

Answer: A. COMMIT

Explanation: COMMIT saves the work of the current transaction permanently. ROLLBACK undoes it, SAVEPOINT only marks a point inside the transaction and BEGIN starts one.

Question 2

A session is in autocommit mode (the default in MySQL, PostgreSQL and SQLite) and no transaction has been started. An UPDATE that changes 5 rows runs successfully. The user then issues ROLLBACK. What is the state of the 5 rows?

  1. They return to their old values, because ROLLBACK undoes the last statement
  2. They are deleted from the table
  3. They stay locked until a COMMIT is issued
  4. They keep the updated values, because the UPDATE was committed as soon as it finished

Answer: D. They keep the updated values, because the UPDATE was committed as soon as it finished

Explanation: In autocommit mode every statement is its own transaction and is committed automatically when it succeeds. There is no open transaction left for ROLLBACK to undo, so the changes stay.

Question 3

Table Coupon(code PRIMARY KEY) holds one row, DIWALI. In PostgreSQL, MySQL (InnoDB) and SQLite, the single statement INSERT INTO Coupon VALUES ('HOLI'), ('DIWALI'), ('EID') is run and fails on the duplicate DIWALI. How many rows does Coupon hold afterwards?

  1. 2
  2. 3
  3. 1
  4. 0

Answer: C. 1

Explanation: A single SQL statement is atomic: if any of its rows breaks a constraint, the whole statement is undone. HOLI is not kept and EID is never added, so the table still holds only the original DIWALI row.

All 20 dml & transactions questions with answers

DML & Transactions: common questions

What are dml & transactions questions?

INSERT, UPDATE, DELETE, COMMIT, ROLLBACK and ACID. They appear in the sql section of many placement tests.

Where can I practise dml & transactions questions with answers for free?

Right here on LogicWiz Exams. Every dml & transactions question has a worked explanation after you answer. Practice is free and needs no sign-up.

How should I practise dml & transactions?

Start with easy questions, then move to medium and hard. Read the explanation after each answer, and come back to the ones you missed.

Start practising

On this page you can start a fresh set of dml & transactions questions, choose easy, medium or hard, and time yourself if you want to. Or practise the whole subject: SQL practice.

More sql topics

Other subjects

LogicWiz Exams home · All practice topics · Placement mock tests · Daily 10 challenge · Test from a job description · LogicWiz Open: free team quiz · Free interview prep