Home » Database » How to update or change data in a MySQL table

How to update or change data in a MySQL table

Changing data in a MySQL table using command line command is not as complicated as it sounds, and the basic problem is the way commands are written in various tutorials and manuals. If you want to update data in a MySQL table, alter a column or a low, you can modify your MySQL command accordingly.

Suppose you want to change data in a single MySQL table cell. In order to achieve this you need to know the name of the column that contains the cell, the row number, or some trait that can uniquely identify that cell. Normally, a complete row in a MySQL table is a complete record and this record is distinguished by a unique record ID, let is say, “rec_id”. Suppose the cell you want to change belongs to rec_id 678 and the name of the cell is “first_name”. Let the MySQL table be “students”. This is how you change the first_name:

update students set first_name=’Suba’ where rec_id=678;

Isn’t it a straightforward command? No matter what value first_name originally contains, it now has Suba in it. Notice that you don’t write “update table students”, you simply write “update students”.