Updating Data in MySQL
Updating Data in MySQL
Updating data in MySQL is very easy with the UPDATE statement. Let's assume we have this table where we need to update the lastname of the second employee.
employeeID | firstname | lastname | joining_date | |
1 | Maxon | Codes | maxon@codes.com | 2024-11-04 14:54:58 |
2 | Kapil | Dev | kapil@codes.com | 2024-11-04 15:44:51 |
To update the lastname in the Employees table we will use the UPDATE command along side SET command and WHERE command. The SET command assigns variables and the WHERE command specifies which record should be updated.
Note: If we don't use the WHERE clause, then all records will be updated.
Example:
After the record is updated, the table will look something like this:
employeeID | firstname | lastname | joining_date | |
1 | Maxon | Codes | maxon@codes.com | 2024-11-04 14:54:58 |
2 | Kapil | Codes | kapil@codes.com | 2024-11-04 15:44:51 |