0
0
MySQLquery~20 mins

DROP and TRUNCATE behavior in MySQL - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
DROP and TRUNCATE Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
query_result
intermediate
2:00remaining
Difference in row count after DROP vs TRUNCATE

Consider a table employees with 100 rows. What will be the number of rows in the table after executing the following commands?

1. TRUNCATE TABLE employees;
2. DROP TABLE employees;

Choose the correct pair of row counts after each command.

AAfter TRUNCATE: 0 rows, After DROP: 0 rows
BAfter TRUNCATE: 100 rows, After DROP: 0 rows
CAfter TRUNCATE: 0 rows, After DROP: Table does not exist
DAfter TRUNCATE: Table does not exist, After DROP: 0 rows
Attempts:
2 left
💡 Hint

Think about what happens to the table structure after each command.

🧠 Conceptual
intermediate
2:00remaining
Transaction behavior of DROP vs TRUNCATE

Which statement correctly describes the transaction behavior of DROP TABLE and TRUNCATE TABLE in MySQL?

ANeither <code>DROP</code> nor <code>TRUNCATE</code> are transactional and cannot be rolled back.
B<code>TRUNCATE</code> is transactional and can be rolled back; <code>DROP</code> is not transactional and cannot be rolled back.
CBoth <code>DROP</code> and <code>TRUNCATE</code> are transactional and can be rolled back.
D<code>DROP</code> is transactional and can be rolled back; <code>TRUNCATE</code> is not transactional and cannot be rolled back.
Attempts:
2 left
💡 Hint

Consider if these commands can be undone inside a transaction.

📝 Syntax
advanced
2:00remaining
Correct syntax to remove all rows but keep table

Which of the following SQL commands correctly removes all rows from a table orders but keeps the table structure intact?

ADROP TABLE orders;
BTRUNCATE TABLE orders;
CDELETE FROM orders;
DREMOVE ALL FROM orders;
Attempts:
2 left
💡 Hint

Think about which command clears data but does not delete the table.

optimization
advanced
2:00remaining
Performance difference between DELETE and TRUNCATE

You want to remove all rows from a large table logs. Which command is generally faster and why?

A<code>TRUNCATE TABLE logs;</code> because it deallocates data pages without logging individual row deletions.
B<code>DELETE FROM logs;</code> because it logs each row deletion for rollback.
C<code>DROP TABLE logs;</code> because it removes the table and data instantly.
D<code>DELETE * FROM logs;</code> because it deletes all rows with a wildcard.
Attempts:
2 left
💡 Hint

Consider how each command handles logging and data removal.

🔧 Debug
expert
2:00remaining
Error when truncating a table with foreign key constraints

You try to run TRUNCATE TABLE orders; but get an error about foreign key constraints. What is the cause?

ATRUNCATE requires the table to be empty before running.
BTRUNCATE cannot be used on tables with any indexes.
CThe table <code>orders</code> does not exist.
DThe table <code>orders</code> has foreign key constraints referencing it, so TRUNCATE is blocked.
Attempts:
2 left
💡 Hint

Think about how foreign keys affect data removal commands.