Home arrow MySQL arrow Page 7 - Speaking SQL (part 1)

Old Data For New - MySQL

Structured Query Language is the language used to communicatewith databases of all shapes, sizes and varieties. If you're building a Webapplication which needs to communicate with a database, and don't knowwhere to start, this article will get you up to speed on the basics ofcreating tables and inserting data into them.

TABLE OF CONTENTS:
  1. Speaking SQL (part 1)
  2. Turntables And Records
  3. Relationships
  4. Not Your Type?
  5. Changing Things Around
  6. Termination With Extreme Prejudice
  7. Old Data For New
By: icarus, (c) Melonfire
Rating: starstarstarstarstar / 7
December 21, 2000

print this article
SEARCH DEV SHED

TOOLS YOU CAN USE

advertisement
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!

 
 
>>> More MySQL Articles          >>> More By icarus, (c) Melonfire
 

blog comments powered by Disqus
   

MYSQL ARTICLES

- Xeround Releases Free Version of MySQL Cloud...
- Oracle Announces New MySQL Specialization
- Constant Contact Chooses SkySQL for MySQL Su...
- Revoke Statement in MySQL
- The Grant Statement in MySQL
- SuccessBricks Announces ClearDB Availability...
- Building a PHP ORM: Deploying a Blog
- TROSYS Launches Free MySQL Manager and Admin...
- Building an ORM in PHP: Domain Modeling
- Building an ORM in PHP
- MySQL Leads Open Source Market, Gets Cluster...
- Oracle Announces Milestone Release for MySQL
- How to Stop SQL Injection Attacks
- New Defragmentation Solution for SQL Server
- Comparison of MyISAM and InnoDB MySQL Databa...


© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 9 - Follow our Sitemap

Dev Shed Tutorial Topics: