|
|
MySQL Queries - Update
Updating your records
Being able to store and retrieve data is useful, but unless you can change it you are seriously limited. MySQL provide an UPDATE query which can do just this:
SELECT * FROM `customers` WHERE `customerid` = 1
Name: Steve Smith - Address: 123 Fake Street - Tax ID: 123456 - Customer ID: 1
UPDATE `customers` SET `name` = 'Steven Smyth' WHERE `customerid` = 1 SELECT * FROM `customers` WHERE `customerid` = 1
Name: Steven Smyth - Address: 123 Fake Street - Tax ID: 123456 - Customer ID: 1
It is very important to remember the WHERE clause in your update statements - otherwise you will change every row in your table! We used the primary key of the table in this example, however you can use the WHERE clause on any column. If you are using your WHERE clause on a column which is not unique be sure that you are sure what you are doing, otherwise you may update records you didn't mean to.
Page Responses
Currently there have been no responses to this page...
If you have anything to contribute to this tutorial, found a bug, or know a better way of achieving the same goal, please leave your response below.
|