Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> MySQL

Cập nhật giá trị trong View MySQL như cập nhật bảng

Cập nhật view MySQL dùng câu lệnh UPDATE giống như bảng, chỉ thay tên bảng bằng tên view. Ví dụ view Info:

mysql> Select * from Info;
+------+---------+------------+
| Id   | Name    | Subject    |
+------+---------+------------+
|  101 | YashPal | History    |
|  105 | Gaurav  | Literature |
|  125 | Raman   | Computers  |
| NULL | Ram     | Computers  |
+------+---------+------------+
4 rows in set (0.00 sec)

Đổi Id từ NULL thành 130 cho Name='Ram':

mysql> Update info set id = 130 where Name = 'Ram';
Query OK, 1 row affected (0.88 sec)
mysql> Select * from Info;
+------+---------+------------+
| Id   | Name    | Subject    |
+------+---------+------------+
|  101 | YashPal | History    |
|  105 | Gaurav  | Literature |
|  125 | Raman   | Computers  |
|  130 | Ram     | Computers  |
+------+---------+------------+
4 rows in set (0.00 sec)