MySQL DatabaseLesson 50Free preview
MySQL Drop Table
This lesson is part of MySQL · All levels
Summary
The table is removed from the database by the DROP TABLE command, which also deletes all the data in it. If you just want to empty the data but maintain the table structure, use TRUNCATE TABLE. MySQL also provides IF EXISTS so that deletions are not error-free when tables do not exist.
Key points
- DROP TABLE removes the structure of the table and all its data
- The TRUNCATE TABLE empties the data but the structure of the table remains.
- TRUNCATE is generally faster and empties the AUTO_INCREMENT value
- DROP TABLE IF EXIST... safe to run when the table may not have been created yet
- Note the foreign key relationship before deleting the table referenced by another table
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.