0
0
SQLquery~20 mins

DELETE vs TRUNCATE behavior in SQL - Practice Questions

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Master of DELETE vs TRUNCATE
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Effect of DELETE on transaction logs
Consider a table Employees with 1000 rows. You run the query:
DELETE FROM Employees;

What is the effect on the transaction log?
SQL
DELETE FROM Employees;
AEach row deletion is logged individually, causing a large transaction log.
BOnly the page deallocations are logged, making the log small.
CNo logging occurs because DELETE is a non-logged operation.
DThe entire table is dropped and recreated, so the log is minimal.
Attempts:
2 left
💡 Hint
Think about how DELETE handles each row versus TRUNCATE.
query_result
intermediate
2:00remaining
TRUNCATE and identity column reset
Given a table Orders with an identity column starting at 1, after inserting 10 rows, you run:
TRUNCATE TABLE Orders;

What happens to the identity value for the next inserted row?
SQL
TRUNCATE TABLE Orders;
AThe identity value is set to NULL and must be reseeded manually.
BThe identity value continues from 11 for the next insert.
CThe identity value resets to 1 for the next insert.
DAn error occurs because TRUNCATE cannot be used on tables with identity columns.
Attempts:
2 left
💡 Hint
TRUNCATE resets the table state including identity counters.
🧠 Conceptual
advanced
2:00remaining
Difference in locking behavior between DELETE and TRUNCATE
Which statement correctly describes the locking behavior when running DELETE vs TRUNCATE on a large table?
ANeither DELETE nor TRUNCATE acquire any locks during execution.
BDELETE acquires a table-level lock; TRUNCATE acquires row-level locks.
CBoth DELETE and TRUNCATE acquire only page-level locks.
DDELETE acquires row-level locks; TRUNCATE acquires a table-level lock.
Attempts:
2 left
💡 Hint
Think about how each command affects concurrency and locking.
🔧 Debug
advanced
2:00remaining
Why does TRUNCATE fail on a table with foreign key constraints?
You try to run:
TRUNCATE TABLE Customers;

but get an error about foreign key constraints. Why does this happen?
ATRUNCATE requires the table to have at least one index to run.
BTRUNCATE cannot be used on tables referenced by foreign keys because it does not check constraints row by row.
CTRUNCATE only works on empty tables, so it fails if rows exist.
DTRUNCATE is not supported on tables with any indexes.
Attempts:
2 left
💡 Hint
Think about how TRUNCATE bypasses row-level operations.
optimization
expert
2:00remaining
Choosing DELETE vs TRUNCATE for performance and rollback needs
You need to remove all rows from a large table quickly but also want the ability to rollback the operation if needed. Which option is best?
AUse DELETE because it logs each row deletion and supports rollback.
BUse DELETE with NOLOGGING option to speed up deletion and allow rollback.
CUse TRUNCATE because it is faster and supports rollback fully.
DUse TRUNCATE with a transaction savepoint to enable rollback.
Attempts:
2 left
💡 Hint
Consider how logging and rollback work for each command.