Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/lsp4you/public_html/connect.php on line 2 LSP4YOU - Learner's Support Publications

SQL - UPDATE Statement

The UPDATE statement is used to modify rows in a table. The UPDATE statement can be used to update a single column or multiple columns of a single row or multiple rows. It can also be used to update a table with values from another table.

UPDATE <table_name> 
SET 
    column_name1 = expr1,
    column_name2 = expr2,
    ...
[WHERE 
    condition];

For Example:
Insert the location for Biosciences department with dept_id 'D05' as 'Main Block South Part'.
mysql> update department 
    -> set location = 'Main Block South Part'
    -> where dept_id = 'D05';
Query OK, 1 row affected (0.16 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql>

To see the changes:
mysql> select * from department;
+---------+----------------+-----------------------+
| dept_id | dept_name      | location              |
+---------+----------------+-----------------------+
| D01     | Computer       | South Block           |
| D02     | Commerce       | E K Block Wing-2      |
| D03     | Administration | E K Block Wing-1      |
| D04     | Psychology     | E K Block Wing-3      |
| D05     | Electronics    | Main Block South Part |
+---------+----------------+-----------------------+
5 rows in set (0.00 sec)

mysql>