And finally, there's an UPDATE command designed to help you change existing values in a table; it looks like this: UPDATE <table_name> SET <field_name> = <new_value> The above command would act on all values in the field <field_name>, changing them all to <new_value>. If you'd like to alter the value in a single field only, you can use the WHERE clause, as with the DELETE command. Using this information, I could update John Doe's email address in the table: mysql>UPDATE members SET email = 'john@somewhere.com' WHERE member_id = 1; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 You can alter multiple fields by separating them with commas. mysql>UPDATE members SET email = 'john@somewhere.com', lname = 'Doe The First WHERE member_id = 2; Query OK, 1 row affected (0.05 sec) Rows matched: 1 Changed: 1 Warnings: 0 And your table will now look something like this: +-----------+-------+---------------+---------+--------------------------+ | member_id | fname | lname | tel | email | +-----------+-------+---------------+---------+--------------------------+ | 1 | John | Doe The First | 1234567 | john@somewhere.com | | 2 | Jane | Doe | 8373728 | jane@site.com | | 3 | Steve | Klingon | 7449373 | steve@alien-race.com | | 4 | Santa | Claus | 9999999 | santa@the-north-pole.com | +-----------+-------+---------------+---------+--------------------------+ 4 rows in set (0.00 sec) And that's about it for the first part of this article. Next time, I'll be showing you how to get your data out of the table with a variety of SELECT statements - so make sure you come back for that!
blog comments powered by Disqus |