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”.

3 thoughts on “How to update or change data in a MySQL table

  1. Origami Folder

    Excellent, thank you!
    When you wrote the mysql command, it would really help to change the look of the mysql commands and the variables, to make it more visual.
    Ex.
    UPDATE students SET first_name=’Suba’ WHERE rec_id=678;
    Or color, italics, etc. Thanks!

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>