DCL & TCL Questions with Answers

19 practice questions on DCL & TCL (SQL) with answers and step-by-step solutions. Try 10 samples below, then practise all 19 free in the AptiNest app.

Sample questions

Question 1Easy

What does the final SELECT return?

CREATE TABLE accounts (id INTEGER PRIMARY KEY, holder TEXT NOT NULL, balance INTEGER CHECK (balance >= 0));
INSERT INTO accounts VALUES (1, 'Uma', 500), (2, 'Vikram', 300);
BEGIN;
UPDATE accounts SET balance = balance - 100 WHERE id = 1;
ROLLBACK;
SELECT balance FROM accounts WHERE id = 1;
  1. 400
  2. 500
  3. NULL
  4. 600

Answer: B. 500

Explanation

ROLLBACK undoes every change made since BEGIN, so the balance is back to 500.

Step-by-step solution

  1. BEGIN starts a transaction, and the UPDATE changes Uma's balance to 400.
  2. ROLLBACK undoes every change since BEGIN, so Uma's balance returns to 500.
  3. The final SELECT reads 500, so the answer is option B.

Why the other options are wrong

  • A. 400 is the balance inside the transaction, but ROLLBACK undid it.
  • C. The balance is not NULL; the row still exists with 500.
  • D. 600 would need the balance to go up, but the update subtracted 100 and was rolled back.

Tip: ROLLBACK undoes all changes made since BEGIN.

Question 2Easy

What does a SAVEPOINT allow inside a transaction?

  1. Rolling back part of the transaction to a named point without undoing the earlier work
  2. Locking a table until COMMIT
  3. Running two transactions in parallel
  4. Committing part of the transaction permanently

Answer: A. Rolling back part of the transaction to a named point without undoing the earlier work

Explanation

ROLLBACK TO savepoint undoes changes made after the savepoint; the transaction stays open and earlier changes remain pending.

Step-by-step solution

  1. A SAVEPOINT marks a named point inside an open transaction.
  2. ROLLBACK TO that savepoint undoes only the changes made after it.
  3. So the answer is option A.

Why the other options are wrong

  • B. A SAVEPOINT does not lock a table; locking is a separate matter.
  • C. A savepoint does not run a second transaction in parallel.
  • D. A savepoint does not commit part of the work; only COMMIT makes changes permanent.

Tip: Use SAVEPOINT to undo part of a transaction while keeping the earlier work.

Question 3Easy

In auto-commit mode (the default in MySQL and SQLite), what happens after each standalone INSERT?

  1. It is rolled back unless COMMIT is issued
  2. It waits until the session ends
  3. It is committed immediately as its own transaction
  4. It is committed only after the next SELECT

Answer: C. It is committed immediately as its own transaction

Explanation

Auto-commit wraps every statement in its own transaction; BEGIN/START TRANSACTION turns it off until COMMIT or ROLLBACK.

Step-by-step solution

  1. In auto-commit mode each statement is its own transaction.
  2. So each INSERT is committed as soon as it succeeds.

Why the other options are wrong

  • A. Nothing is rolled back by default.
  • B. It does not wait for the session to end.
  • D. A SELECT does not trigger a commit.

Tip: BEGIN turns auto-commit off.

Question 4Easy

Which commands belong to DCL (Data Control Language)?

  1. SELECT and INSERT
  2. ALTER and DROP
  3. COMMIT and ROLLBACK
  4. GRANT and REVOKE

Answer: D. GRANT and REVOKE

Explanation

DCL controls access privileges on database objects.

Step-by-step solution

  1. DCL (Data Control Language) controls access privileges.
  2. GRANT gives privileges and REVOKE takes them away.
  3. So the answer is option D.

Why the other options are wrong

  • A. SELECT and INSERT are DML commands, not access control.
  • B. ALTER and DROP are DDL commands that change structure.
  • C. COMMIT and ROLLBACK are TCL commands that manage transactions.

Tip: GRANT and REVOKE are the two DCL commands.

Question 5Medium

What does WITH GRANT OPTION add to GRANT SELECT ON sales TO analyst WITH GRANT OPTION; (standard SQL / MySQL)?

  1. analyst gets every privilege on sales
  2. The privilege cannot be revoked later
  3. analyst can also grant SELECT on sales to other users
  4. analyst becomes the owner of sales

Answer: C. analyst can also grant SELECT on sales to other users

Explanation

WITH GRANT OPTION lets the grantee pass the same privilege on to others.

Step-by-step solution

  1. WITH GRANT OPTION lets the grantee pass the same privilege to others.
  2. So analyst can grant SELECT on sales to other users.
  3. The answer is option C.

Why the other options are wrong

  • A. Only SELECT is granted; WITH GRANT OPTION does not give every privilege.
  • B. The privilege can still be revoked; the option is about passing it on.
  • D. The grantee does not become the owner of sales.

Tip: WITH GRANT OPTION lets the grantee pass the privilege on, so use it carefully.

Question 6Medium

What does the final SELECT return?

CREATE TABLE accounts (id INTEGER PRIMARY KEY, holder TEXT NOT NULL, balance INTEGER CHECK (balance >= 0));
INSERT INTO accounts VALUES (1, 'Uma', 500), (2, 'Vikram', 300);
BEGIN;
UPDATE accounts SET balance = 0 WHERE id = 2;
COMMIT;
BEGIN;
DELETE FROM accounts;
ROLLBACK;
SELECT SUM(balance) FROM accounts;
  1. 800
  2. NULL
  3. 0
  4. 500

Answer: D. 500

Explanation

The first transaction is committed (account 2 becomes 0). The DELETE is rolled back, so both rows remain: 500 + 0 = 500.

Step-by-step solution

  1. The first transaction commits, so account 2's balance becomes 0.
  2. The second transaction deletes both rows, but ROLLBACK restores them.
  3. The final SUM is 500 + 0 = 500, so the answer is option D.

Why the other options are wrong

  • A. Account 2 is 0 after the committed update, so the sum is not 800.
  • B. The rows are restored, so the sum is not NULL.
  • C. Account 1 keeps 500, so the sum is not 0.

Tip: Rolled-back DELETEs restore the rows; only committed changes stay.

Question 7Medium

What does the final SELECT return?

matches
mid | home   | away   | hg   | ag
1   | Lions  | Tigers | 2    | 1
2   | Bears  | Lions  | 0    | 0
3   | Tigers | Bears  | 3    | 2
4   | Lions  | Bears  | 1    | 3
5   | Tigers | Lions  | NULL | NULL
BEGIN;
UPDATE matches SET hg = 1, ag = 1 WHERE mid = 5;
SAVEPOINT p;
DELETE FROM matches WHERE hg = ag;
ROLLBACK TO p;
RELEASE p;
COMMIT;
SELECT COUNT(*) FROM matches WHERE hg = ag;
  1. 0
  2. 1
  3. 2
  4. 3

Answer: C. 2

Explanation

The delete is undone by ROLLBACK TO p, but the earlier update is kept and committed: matches 2 and 5 are now draws.

Step-by-step solution

  1. The first UPDATE sets match 5 to 1 to 1, so it is a draw; this is kept after COMMIT.
  2. The DELETE removes matches 2 and 5 (both draws), then ROLLBACK TO p restores them.
  3. After COMMIT, draws are matches 2 (0 to 0) and 5 (1 to 1): the count is 2 (option C).

Why the other options are wrong

  • A. Match 5 was updated to 1 to 1 before the savepoint and is kept, so draws exist.
  • B. Match 2 (0 to 0) is also a draw and is kept, so the count is not 1.
  • D. The DELETE was undone by ROLLBACK TO, so there is no third draw.

Tip: ROLLBACK TO a savepoint undoes only what happened after it; earlier changes stay in the transaction.

Question 8Medium

What does the final SELECT return?

CREATE TABLE accounts (id INTEGER PRIMARY KEY, holder TEXT NOT NULL, balance INTEGER CHECK (balance >= 0));
INSERT INTO accounts VALUES (1, 'Uma', 500), (2, 'Vikram', 300);
BEGIN;
INSERT INTO accounts VALUES (3, 'Zoya', 50);
SAVEPOINT a;
INSERT INTO accounts VALUES (4, 'Ravi', 60);
SAVEPOINT b;
DELETE FROM accounts WHERE id = 1;
ROLLBACK TO a;
COMMIT;
SELECT COUNT(*) FROM accounts;
  1. 5
  2. 2
  3. 3
  4. 4

Answer: C. 3

Explanation

Rolling back to a undoes everything after it — the insert of Ravi and the delete — leaving the 2 original rows plus Zoya.

Step-by-step solution

  1. Zoya is inserted first, giving 3 rows, and then savepoint a is set.
  2. Ravi is inserted and savepoint b is set; then Uma (id 1) is deleted.
  3. ROLLBACK TO a undoes the Ravi insert and the delete, so Uma, Vikram and Zoya remain: COUNT is 3, option C.

Why the other options are wrong

  • A. 5 is more rows than could ever exist at once here, and the rollback removed Ravi anyway.
  • B. 2 would mean Zoya's insert was undone, but it came before savepoint a.
  • D. 4 would mean Ravi's insert was kept, but ROLLBACK TO a undid it.

Tip: ROLLBACK TO a savepoint undoes only the work done after that savepoint.

Question 9Hard

Which statement about roles is correct in standard SQL / MySQL 8?

  1. Privileges can be granted to a role, and the role granted to many users, so permissions are managed in one place
  2. Roles can hold only SELECT privileges
  3. A role is a schema that owns tables
  4. Granting a role copies its current privileges once and never updates

Answer: A. Privileges can be granted to a role, and the role granted to many users, so permissions are managed in one place

Explanation

CREATE ROLE, GRANT ... TO role and GRANT role TO user let administrators change one role to update every member’s access.

Step-by-step solution

  1. A role is a named group of privileges.
  2. Privileges can be granted to a role, and the role can be granted to many users.
  3. Changing the role then changes every member's access, so option A is correct.

Why the other options are wrong

  • B. A role can hold any privileges, not only SELECT.
  • C. A role is not a schema; a schema is a namespace that holds tables.
  • D. Members get the role's privileges, and later changes to the role also reach them.

Tip: Grant privileges to a role, then grant the role to users, so access is managed in one place.

Question 10Hard

Two transactions each update account A then account B, but in opposite order, and each waits for the other’s lock. What is this situation called, and how do DBMSs usually resolve it?

  1. A dirty read; the DBMS retries both reads
  2. A deadlock; the DBMS detects it and rolls back one victim transaction
  3. A phantom; the DBMS raises the isolation level
  4. A lost update; the DBMS merges both writes

Answer: B. A deadlock; the DBMS detects it and rolls back one victim transaction

Explanation

A cycle of waits is a deadlock. Lock managers detect the cycle (or use timeouts) and abort one transaction so the other can proceed.

Step-by-step solution

  1. Each transaction holds a lock the other needs and waits for it, which forms a cycle.
  2. A circular wait of this kind is called a deadlock.
  3. The DBMS detects the cycle, or times out, and rolls back one victim so the other can finish; option B.

Why the other options are wrong

  • A. A dirty read is reading uncommitted data, not a lock cycle, and retrying reads is not the fix.
  • C. A phantom is new rows appearing in a query, not a cycle of waiting locks.
  • D. A lost update is one write overwriting another; the writes are not merged.

Tip: Access rows in the same order in every transaction to reduce deadlocks.

Practise all 19 questions free

The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.

Open this topic in the app →

Related topics

See all SQL topics · All topics