These commands help you remove data or tables from a database quickly and safely.
When you want to remove all rows from a table but keep the table structure.
When you want to delete specific rows from a table.
When you want to completely remove a table and its data from the database.
Syntax
SQL
TRUNCATE TABLE table_name;
DELETEFROM table_name WHERE condition;
DROPTABLE table_name;
TRUNCATE removes all rows fast but keeps the table ready for new data.
DELETE removes rows one by one and can use conditions to remove specific rows.
Examples
Removes all rows from the 'employees' table quickly.
SQL
TRUNCATE TABLE employees;
Deletes only employees who work in the Sales department.
SQL
DELETEFROM employees WHERE department = 'Sales';
Deletes the entire 'employees' table and all its data.
SQL
DROPTABLE employees;
Sample Program
This example shows how DELETE removes one row, TRUNCATE removes all rows fast, and DROP removes the whole table.
SQL
CREATETABLE fruits (id INT, name VARCHAR(20));
INSERTINTO fruits VALUES (1, 'Apple'), (2, 'Banana'), (3, 'Cherry');
-- Delete one rowDELETEFROM fruits WHERE name = 'Banana';
-- Show remaining rowsSELECT * FROM fruits;
-- Remove all rows fast
TRUNCATE TABLE fruits;
-- Show rows after truncateSELECT * FROM fruits;
-- Drop the tableDROPTABLE fruits;
OutputSuccess
Important Notes
TRUNCATE is faster than DELETE because it does not log individual row deletions.
DELETE can use WHERE to remove specific rows; TRUNCATE cannot.
DROP removes the table structure and data; use it carefully.
Summary
TRUNCATE clears all rows quickly but keeps the table.
DELETE removes rows selectively and logs each deletion.
DROP deletes the entire table and its data permanently.
Practice
(1/5)
1. Which SQL command removes all rows from a table quickly but keeps the table structure intact?
easy
A. TRUNCATE
B. DELETE
C. DROP
D. ALTER
Solution
Step 1: Understand the effect of TRUNCATE
TRUNCATE removes all rows quickly without logging each row deletion, but keeps the table structure.
Step 2: Compare with other commands
DELETE removes rows but logs each deletion, DROP deletes the entire table, and ALTER changes table structure.
Final Answer:
TRUNCATE -> Option A
Quick Check:
Fast row removal keeping table = TRUNCATE [OK]
Hint: TRUNCATE clears all rows fast but keeps table [OK]
Common Mistakes:
Confusing DROP with TRUNCATE
Thinking DELETE is faster than TRUNCATE
Assuming ALTER removes data
2. Which of the following is the correct syntax to delete all rows from a table named Employees?
easy
A. TRUNCATE TABLE Employees;
B. DELETE * FROM Employees;
C. DELETE FROM Employees;
D. DROP TABLE Employees;
Solution
Step 1: Recall DELETE syntax
The correct syntax to delete rows is DELETE FROM table_name; without the asterisk.
Step 2: Check other options
DELETE * FROM is invalid syntax, TRUNCATE and DROP are different commands.
Final Answer:
DELETE FROM Employees; -> Option C
Quick Check:
Correct DELETE syntax = DELETE FROM [OK]
Hint: DELETE syntax has no * after DELETE keyword [OK]
Common Mistakes:
Using DELETE * instead of DELETE FROM
Confusing TRUNCATE with DELETE syntax
Using DROP to remove rows only
3. Given a table Products with 1000 rows, what will be the result after running TRUNCATE TABLE Products;?
medium
A. The table is deleted completely, including its structure.
B. All rows are removed quickly, but the table remains for new data.
C. Only rows matching a condition are deleted.
D. An error occurs because TRUNCATE requires a WHERE clause.
Solution
Step 1: Understand TRUNCATE effect on data
TRUNCATE TABLE removes all rows quickly without logging each deletion but keeps the table structure intact.
Step 2: Check other options
The table is deleted completely, including its structure. describes DROP, Only rows matching a condition are deleted. describes DELETE with condition, An error occurs because TRUNCATE requires a WHERE clause. is incorrect because TRUNCATE does not allow WHERE but does not error for missing WHERE.
Final Answer:
All rows are removed quickly, but the table remains for new data. -> Option B
Quick Check:
TRUNCATE clears rows, keeps table = All rows are removed quickly, but the table remains for new data. [OK]
Hint: TRUNCATE clears all rows fast, table stays [OK]
Common Mistakes:
Thinking TRUNCATE deletes the table
Expecting TRUNCATE to support WHERE clause
Confusing TRUNCATE with DELETE
4. You run the command DELETE FROM Customers WHERE CustomerID = 10; but get an error. Which of these is the most likely cause?
medium
A. The CustomerID column is misspelled or missing.
B. You used DELETE without specifying a table.
C. You cannot use WHERE with DELETE.
D. The table Customers does not exist.
Solution
Step 1: Check command syntax
The syntax DELETE FROM Customers WHERE CustomerID = 10; is correct if the table and column exist.
Step 2: Identify error cause
If an error occurs, likely the column CustomerID is misspelled or missing, causing the error.
Final Answer:
The CustomerID column is misspelled or missing. -> Option A
Quick Check:
Column error causes DELETE failure = The CustomerID column is misspelled or missing. [OK]
Hint: Check column names carefully if DELETE with WHERE fails [OK]
Common Mistakes:
Assuming DELETE cannot use WHERE
Ignoring table existence errors
Confusing syntax errors with data errors
5. You want to permanently remove a table named Orders and all its data from the database. Which command should you use and why?
hard
A. DELETE FROM Orders; because it removes all rows and keeps the table.
B. TRUNCATE TABLE Orders; because it quickly deletes all rows but keeps the table.
C. ALTER TABLE Orders DROP; because it removes the table structure.
D. DROP TABLE Orders; because it deletes the table and all its data permanently.
Solution
Step 1: Understand the goal
The goal is to remove the table and all its data permanently from the database.
Step 2: Compare commands
DELETE and TRUNCATE remove data but keep the table. ALTER TABLE DROP is invalid syntax. DROP TABLE removes the table and data permanently.
Final Answer:
DROP TABLE Orders; because it deletes the table and all its data permanently. -> Option D
Quick Check:
Remove table and data permanently = DROP TABLE [OK]
Hint: DROP removes table and data permanently [OK]
Common Mistakes:
Using DELETE or TRUNCATE to remove table
Trying ALTER TABLE DROP which is invalid
Confusing DROP with DELETE
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.