UPDATE and DELETE Commands
Without any further instruction, see if you can follow what is happening below:
mysql> insert into people
-> values ('fadams', 'Adams', 'Frank', 'M', '');
Query OK, 1 row affected (0.01 sec)
mysql> select * from people;
+----------+-----------+------------+-------------+-------------------+ | ID | NAME_LAST | NAME_FIRST | MI | POSITION | +----------+-----------+------------+-------------+-------------------+ | rjones | Jones | Robert | T | Manager | | tjones | Jones | Tyler | R | Technician | | bsmith | Smith | Barbara | N | Clerk | | nsmith | Smith | Nancy | B | Manager | | fadams | Adams | Frank | M | | +----------+-----------+------------+-------------+-------------------+5 rows in set (0.00 sec) mysql> update people set NAME_FIRST = '' where ID = 'fadams'; Query OK, 1 row affected (0.02 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from people;
+----------+-----------+------------+-------------+-------------------+ | ID | NAME_LAST | NAME_FIRST | MI | POSITION | +----------+-----------+------------+-------------+-------------------+ | rjones | Jones | Robert | T | Manager | | tjones | Jones | Tyler | R | Technician | | bsmith | Smith | Barbara | N | Clerk | | nsmith | Smith | Nancy | B | Manager | | fadams | Adams | | M | | +----------+-----------+------------+-------------+-------------------+5 rows in set (0.00 sec) mysql> update people set NAME_FIRST = 'Fred', POSITION = 'Clerk' -> where ID = 'fadams'; Query OK, 1 row affected (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 0 mysql> select * from people;
+--------+-----------+------------+----+------------+ | ID | NAME_LAST | NAME_FIRST | MI | POSITION | +--------+-----------+------------+----+------------+ | rjones | Jones | Robert | T | Manager | | tjones | Jones | Tyler | R | Technician | | bsmith | Smith | Barbara | N | Clerk | | nsmith | Smith | Nancy | B | Manager | | fadams | Adams | Fred | M | Clerk | +--------+-----------+------------+----+------------+5 rows in set (0.00 sec) mysql> delete from people where ID = 'fadams'; Query OK, 1 row affected (0.03 sec) mysql> select * from people;
+--------+-----------+------------+----+------------+ | ID | NAME_LAST | NAME_FIRST | MI | POSITION | +--------+-----------+------------+----+------------+ | rjones | Jones | Robert | T | Manager | | tjones | Jones | Tyler | R | Technician | | bsmith | Smith | Barbara | N | Clerk | | nsmith | Smith | Nancy | B | Manager | +--------+-----------+------------+----+------------+4 rows in set (0.00 sec) mysql>
(Don't do either of these) If we wrote delete from people, we would delete all records from people. If we wrote drop table people, we would drop the whole table from the database.