4. You want to remove a table named orders completely, but accidentally run TRUNCATE orders;. What is the problem with this command?
medium
A. It will cause a syntax error because TABLE keyword is missing.
B. It will delete the table and all its data.
C. It will only delete some rows, not all.
D. It will rename the table instead of deleting.
Solution
Step 1: Check syntax of TRUNCATE command
The correct syntax requires the keyword TABLE: TRUNCATE TABLE orders;.
Step 2: Identify error from missing keyword
Omitting TABLE causes a syntax error in MySQL.
Final Answer:
It will cause a syntax error because TABLE keyword is missing. -> Option A
Quick Check:
TRUNCATE requires TABLE keyword [OK]
Hint: Always include TABLE keyword in TRUNCATE [OK]
Common Mistakes:
Omitting TABLE keyword in TRUNCATE
Expecting TRUNCATE to delete table structure
Confusing TRUNCATE with DROP syntax
5. You have a table customers with foreign key constraints referencing it from other tables. Which command should you use to quickly remove all data from customers without dropping the table and without breaking foreign key constraints?
hard
A. ALTER TABLE customers DROP;
B. TRUNCATE TABLE customers;
C. DROP TABLE customers;
D. DELETE FROM customers;
Solution
Step 1: Understand foreign key constraints effect
TRUNCATE TABLE cannot be used if foreign keys reference the table; it will cause an error.
Step 2: Choose command that removes data safely
DELETE FROM customers; removes all rows and respects foreign key constraints.
Step 3: Confirm other options
DROP TABLE deletes the table, breaking references; ALTER TABLE DROP is invalid syntax.
Final Answer:
DELETE FROM customers; -> Option D
Quick Check:
DELETE respects foreign keys, TRUNCATE does not [OK]
Hint: Use DELETE when foreign keys exist, not TRUNCATE [OK]
Common Mistakes:
Using TRUNCATE despite foreign key constraints
Using DROP which deletes the table
Trying invalid ALTER TABLE DROP syntax
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.