UPDATE and DELETE Commands


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.


Alter, Insert   < <  PREVIOUS   Table of Contents NEXT  > >   Functions

Developed with HTML-Kit
Sandersongs Web Tutorials
Contact the Webmasterwith comments.
©2024, by Bill Sanders, all rights reserved.
This domain had 3,320 different visits in the last 30 days.
http://sandersongs.com/PHPsqlCourse/SQL04.php
This page was last modified on our server on 11 Jul 2021
and last refreshed on our server at 9:10 am, UTC
This file took 0.01222 seconds to process.