Python MySQLLesson 119Free preview
MySQL Delete
This lesson is part of Python · All levels
Summary
This lesson explains how to delete a row of data from a MySQL table using the DELETE command. You'll learn the importance of the WHERE clause to not accidentally delete the entire contents of the table. As with inserts and updates, the result of permanent new deletions after conn.commit() is called.
Key points
- DELETE FROM name_table without WHERE deletes all the rows in the table.
- Always use a specific WHERE so that only the target line is missing.
- Cursor.rowcount reports how many lines were successfully deleted.
- DELETE deletes only the data line, while DROP deletes the entire table.
- The deletion of data via Python must still end with conn.commit().
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.