How to Update Table Data in MySql

How to Update Table Data in MySql - The update process can be done at any time if there is data or records in a table that needs to be fixed. This update process does not add new data (record), but fixes the old data. Changes that occur in the update process is permanent, meaning that after the command is executed can not be canceled (undo).
Learn first about previous articles: How to Insert Data Into The Table in MySql
The general form of SQL commands to edit a record or data from a table is as follows:
UPDATE table_name SET field1=’ newvalue’ [WHERE condition];
At the command to update above:
  • UPDATE is a basic command to change table records.
  • table_name is the name of the table to be changed recordnya.
  • The SET command is followed by the fields to be changed which is followed by the change of contents of each field. To change the value of multiple fields at once, use the comma (,) to separate each field.
  • WHERE command is followed by certain conditions that determine which record.
To be edited (updated). This WHERE command may or may not.
If WHERE is not added to the update command all records in the table will change.

How to edit data table in mysql

Consider some examples of the following UPDATE student table commands!
1. Change the address to "Semarang" for students who have studentnumber 201051162.
UPDATE student SET address='Semarang' WHERE studentnumber='201051162';
And if the above query is executed then the results will be displayed as follows:
Query OK, 1 row affected (0.03 sec)
Rows matched: 1 Changed: 1 Warnings: 0

How to Update Table Data in MySql

2. Change the date of birth to "May 1, 1995" and the address becomes "Bandung" for students who have nim 201052166
UPDATE student SET dateofbirth='1995-05-01', address='Bandung' WHERE studentnumber='201052166';
And if the above query is executed then the results will be displayed as follows:
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0

How to Update Table Data in MySql

That is the tutorial we can provide about How to update table data in mysql, hopefully can increase your knowledge in learning php programming language.

Comments