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
escort Bursa Bursa escort Antalya eskort
   

MYSQL ARTICLES

- Oracle Unveils MySQL 5.6
- MySQL Vulnerabilities Threaten Databases
- MySQL Cloud Options Expand with Google Cloud...
- MySQL 5.6 Prepped to Handle Demanding Web Use
- ScaleBase Service Virtualizes MySQL Databases
- Oracle Unveils MySQL Conversion Tools
- Akiban Opens Database Software for MySQL Use...
- Oracle Fixes MySQL Bug
- MySQL Databases Vulnerable to Password Hack
- MySQL: Overview of the ALTER TABLE Statement
- MySQL: How to Use the GRANT Statement
- MySQL: Creating, Listing, and Removing Datab...
- MySQL: Create, Show, and Describe Database T...
- MySQL Data and Table Types
- McAfee Releases Audit Plugin for MySQL Users

Developer Shed Affiliates

 


Dev Shed Tutorial Topics: