Python MySQLLesson 121Free preview
MySQL Update
This lesson is part of Python · All levels
Summary
This lesson explains how to update existing data in a MySQL table with the UPDATE command. The SET clause specifies the column with its new value, whereas the WHERE restricts any line that can be changed. Like other written operations, changes are only stored after the conn.commit() is called.
Key points
- Basic format: UPDATE the name_table of the SET column = the WHERE value of the condition.
- Without WHERE, the entire row on the table will be updated to the same value.
- The value should be given as a parameter %s for the security of SQL injection.
- Cursor.rowcount shows how many lines have actually changed.
- Expressions can use long values, for example SET price = price * 1.1 for a 10 percent increase.
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.