Saturday, March 22, 2008

MySQL Update And Delete

The statement UPDATE is used to change the value in a table. For example to change to species name from Turtle to Dog

mysql> UPDATE species SET name = 'Dog' WHERE name = 'Turtle';
Query OK, 1 row affected (0.02 sec)
Rows matched: 1 Changed: 1 Warnings: 0

mysql> SELECT * FROM species;
+----+-------+
| id | name |
+----+-------+
| 1 | Cat |
| 2 | Bird |
| 3 | Fish |
| 4 | Dog |
+----+-------+
4 rows in set (0.00 sec)


Delete Data

The DELETE statement deletes rows from a table that satisfy the condition given by the WHERE clause. For example to delete a record from species table where id equals 1

mysql> DELETE FROM species WHERE id = 1;
Query OK, 1 row affected (0.00 sec)

mysql> SELECT * FROM species;
+----+-------+
| id | name |
+----+-------+
| 2 | Bird |
| 3 | Fish |
| 4 | Dog |
+----+-------+
3 rows in set (0.01 sec)

Now that you alredy know the basics of MySQL it's time to continue the tutorial. You will start learning how to connect to MySQL database using PHP.

By the way this is a good time for you to download download the MySQL reference manual ( if you haven't done so). It covers in detail about everything you need to know about MySQL. As with the PHP manual you should download the compiled HTML version of MySQL manual because it's easier to browse than other formats.

No comments: