MySQL Updating and Deleting Data

You can update and delete data using the the UPDATE and DELETE commands. To update a column the syntax is:

UPDATE table_name set column_name = value;

All the rows in that column will be updated. However you can use the WHERE clause so only certain fields are updated:

UPDATE table_name set column_name = value WHERE column_name = value;

Example

UPDATE Games SET gRating = 8;

This will update the column gRating to 8, and applies to all rows.

Example – WHERE CLAUSE

UPDATE Games SET gRating = 10 WHERE gName = 'Left For Dead 2';

Deleting Rows

You can delete rows from a column using the following syntax:

DELETE FROM table_name;

This deletes all the rows in that column. To delete specific rows use the WHERE clause:

DELETE FROM table_name WHERE column_name = value;

Example

DELETE FROM Consoles WHERE Id = 1;

This will delete the first row in the Consoles table.

Summary

MySQL is easy to learn and become comfortable with, as the majority of the syntax is plain English, unlike PHP or C#. This tutorial outlined how to update and delete rows, and showed that the WHERE clause can filter and delete or update certain fields. These tutorials were developed to give beginners an overview of MySQL using the CLC.