Home >Database >Mysql Tutorial >After updating any value in a specific view, does MySQL update the same value in the base table and its associated views (if any)?
Yes, MySQL will update the value, if it is updated in a view, in the base table as well as in its associated views. To illustrate it we are taking the example of table Student_info having the following data −
mysql> Select * from student_info; +------+---------+------------+------------+ | id | Name | Address | Subject | +------+---------+------------+------------+ | 101 | YashPal | Amritsar | History | | 105 | Gaurav | Chandigarh | Literature | | 125 | Raman | Shimla | Computers | | NULL | Ram | Jhansi | Computers | +------+---------+------------+------------+ 4 rows in set (0.00 sec)
The following is the view 'Info' created based on the table 'Student_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)
Now in the following query we will update the view 'Info' −
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 result set shows that view 'Info' has been updated.
mysql> Select * from student_info; +------+---------+------------+------------+ | id | Name | Address | Subject | +------+---------+------------+------------+ | 101 | YashPal | Amritsar | History | | 105 | Gaurav | Chandigarh | Literature | | 125 | Raman | Shimla | Computers | | 130 | Ram | Jhansi | Computers | +------+---------+------------+------------+ 4 rows in set (0.00 sec)
The above result set shows that when we update the view named 'info', the base table is also updated.
The following is a view named 'info_less' created based on the view 'info'. When we update the view 'info', it will also be updated.
mysql> Select * from info_less; +------+-------+-----------+ | Id | Name | Subject | +------+-------+-----------+ | 125 | Raman | Computers | | 130 | Ram | Computers | +------+-------+-----------+ 2 rows in set (0.00 sec)
The above is the detailed content of After updating any value in a specific view, does MySQL update the same value in the base table and its associated views (if any)?. For more information, please follow other related articles on the PHP Chinese website!