Home > Database > Mysql Tutorial > How can we update any value in a MySQL view like we update a value in a MySQL table?

How can we update any value in a MySQL view like we update a value in a MySQL table?

WBOY
Release: 2023-09-19 16:57:02
forward
773 people have browsed it

我们如何像更新 MySQL 表中的值一样更新 MySQL 视图中的任何值?

As we all know that with the help of UPDATE statement we can update values ​​in MySQL tables and in similar way we can update values ​​in MySQL views. The syntax of the UPDATE statement is the same, except that in place of the table name we must provide the name of the view. We get the following data from the view named "Info" to illustrate the above concept-

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)
Copy after login

Now, suppose we want to change the value of Id from NULL to any other value, then with the help of the following query, we can Update the value of the view-

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)
Copy after login

The above is the detailed content of How can we update any value in a MySQL view like we update a value in a MySQL table?. For more information, please follow other related articles on the PHP Chinese website!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template