O'Reilly logo

Managing & Using MySQL, 2nd Edition by Hugh E. Williams, Randy Yarger, George Reese, Tim King

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Updates

The insertion of new rows into a database is just the start of data management. Unless your database is read-only, you will probably also need to make periodic changes to the data. The standard SQL modification statement looks like this:

UPDATE table_name
SET column1=value1, column2=value2, ..., columnN=valueN
[WHERE clause]

You specifically name the table you want to update and the values you want to assign in the SET clause, and then identify the rows to be affected in the WHERE clause. If you fail to specify a WHERE clause, MySQL will update every row in the table.

In addition to assigning literal values to a column, you can also calculate the values. You can even calculate the value based on a value in another column:

UPDATE years
SET end_year = begin_year+5

This command sets the value in the end_year column equal to the value in the begin_year column plus 5 for each row in that table.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required