Python MySQLLesson 120Free preview
MySQL Drop Table
This lesson is part of Python · All levels
Summary
This lesson discusses how to permanently delete tables from MySQL using the DROP TABLE command. You'll also be able to distinguish between the DROP TABLE and the TRUNCATE TABLE and the DELETE, which have varying deletion rates. Using IF NOT EXISTS makes code more secure when the script is run repeatedly.
Key points
- DROP TABLE name_table removes the table with all its structure and contents.
- The TRUNCATE TABLE empties all the rows but the structure of the table remains.
- IF NOT EXISTS prevents errors when tables have never been created.
- The deletion of the table is permanent and cannot be cancelled without backup.
- Secure sequence: make a connection, make a cursor, execute a DROP, commit, and then shut down the connection.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.