To drop the table and the database
Expt. No.36
Page No.72
Drop the table and database
Aim
To remove the STUDENT table and then the school database.
Concepts used
Queries
USE school;SHOW TABLES;DROP TABLE student;SHOW TABLES;DROP DATABASE school;
A marked line continues the line above it. In your file, write it on the same line.
Output
mysql> USE school;
Database changed
mysql> SHOW TABLES;
+------------------+
| Tables_in_school |
+------------------+
| student |
+------------------+
1 row in set
mysql> DROP TABLE student;
Query OK, 0 rows affected
mysql> SHOW TABLES;
Empty set
mysql> DROP DATABASE school;
Query OK, 0 rows affected
✓ Printed by running this query set, not typed by hand.
Result
After DROP TABLE, SHOW TABLES returned an empty set; DROP DATABASE then removed the school database. Both are permanent.
Viva voce: what the examiner may ask
01Can a dropped table be recovered with a command?
No. DROP removes it permanently; only a backup can restore it.
02What is the difference between DROP TABLE and DELETE FROM?
DROP TABLE removes the table and its structure; DELETE removes rows but keeps the table.
03What does SHOW TABLES list?
The tables in the current database.
Variations for the lab test
- Use
DROP TABLE IF EXISTS student;twice and see that the second gives no error. - Create the database and table again from the earlier queries.
- Drop a table that doesn't exist and read the error.
! Common mistake Running DROP DATABASE on the wrong database deletes all its tables at once; check the name first.