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?
- COMMIT
- ROLLBACK
- SAVEPOINT
- 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?
- They return to their old values, because ROLLBACK undoes the last statement
- They are deleted from the table
- They stay locked until a COMMIT is issued
- 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?
- 2
- 3
- 1
- 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
- Table Account: acc_no | holder | balance 101 | Farah | 5000 102 | Gopal |…
- Table Account: acc_no | holder | balance 101 | Farah | 5000 102 | Gopal |…
- Table Account: acc_no | holder | balance 101 | Farah | 5000 102 | Gopal |…
- Which statement ends a transaction and makes all of its changes permanent?
- During a UPI transfer, ₹500 is debited from Meena's account, but the credit to…
- Table Account: acc_no | holder | balance 101 | Farah | 5000 102 | Gopal |…
- Table Account: acc_no | holder | balance 101 | Farah | 5000 102 | Gopal |…
- Table Account: acc_no | holder | balance 101 | Farah | 5000 102 | Gopal |…
- Table Account: acc_no | holder | balance 101 | Farah | 5000 102 | Gopal |…
- Table Account: acc_no | holder | balance 101 | Farah | 5000 102 | Gopal |…
- Table Account: acc_no | holder | balance 101 | Farah | 5000 102 | Gopal |…
- Table Account: acc_no | holder | balance 101 | Farah | 5000 102 | Gopal |…
- A session is in autocommit mode (the default in MySQL, PostgreSQL and SQLite)…
- Table Cart: item | qty Rice | 1 Which items does the SELECT return after these…
- Table Account: acc_no | holder | balance 101 | Farah | 5000 102 | Gopal |…
- Table Wallet: user_name | points Lalit | 100 Mona | NULL Nitin | 50 Every user…
- Table Account: acc_no | holder | balance 101 | Farah | 5000 102 | Gopal |…
- Table Account: acc_no | holder | balance 101 | Farah | 5000 102 | Gopal |…
- Table Coupon(code PRIMARY KEY) holds one row, DIWALI. In PostgreSQL, MySQL…
- Table Customer: id | name | total 1 | Omkar | 0 2 | Pallavi | 0 3 | Qasim | 0…
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
- SELECT, WHERE & ORDER BY: Filtering, DISTINCT, IN, BETWEEN, LIKE, sorting and LIMIT.
- SQL Joins: Inner, left, right, full, cross and self joins, and row counts.
- Aggregates & GROUP BY: COUNT, SUM, AVG, grouping and HAVING versus WHERE.
- Subqueries & CTEs: Scalar and correlated subqueries, IN, EXISTS and WITH.
- Window Functions: ROW_NUMBER, RANK, DENSE_RANK, PARTITION BY, LAG and running totals.
- NULL Handling: Three-valued logic, IS NULL, COALESCE and NULL in aggregates.
- SQL Functions & CASE: CASE WHEN, conditional aggregation, string and numeric functions.
- UNION, INTERSECT & EXCEPT: Combining results, duplicates and column rules.
- Tables, Keys & Constraints: CREATE, ALTER, primary and foreign keys, UNIQUE and CHECK.
Other subjects
- Quantitative Aptitude: Arithmetic, percentages, time and work, speed, probability and data interpretation: the numerical section of every fresher test.
- Logical Reasoning: Series, coding-decoding, arrangements, syllogisms and puzzles: the section that separates prepared candidates from the rest.
- Verbal Ability: Vocabulary, grammar, reading comprehension and sentence order: tested in nearly every IT services hiring exam.
- Technical & Programming: CS fundamentals, output prediction and pseudo-code: the technical MCQ round for IT roles.
- Python: Python quizzes by topic, from types and strings to classes and generators: output prediction and interview concepts.
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