Abbey Workshop

MySQL: Updating a MySQL Record

The update keyword is used to update individual database records.

Updating a Column

To update a record, the update keyword is used as follows:

		
update tablename set columnname = "newdata" where columnname = value;

You supply the tablename, columnname, data and the columnname and value that determine which rows are updated. Here is an example.

update dstore set Title = "New Title" where pagno = 1;

This command would replace the title column with the new data for any row that meets the requirement in the where clause. The where clause depends on the type of data in the column. If the column contains a char or text field, then a string would be used.

Updating Multiple Columns

To update multiple columns, the format looks something like this.

update tablename set columnname = "newdata", columnname = "newdata", columnname =
number where columnname = value;

Each column and its data is merely separated by commas. Here an example of two columns being updated.

update dstore set Title = "New Title", Category = "PHP" where pagno = 1;