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)
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)
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!