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)
以下是基於表格'Student_info' 建立的視圖'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)
現在在下面的查詢中,我們將更新視圖'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)
上述結果集顯示檢視'Info' 已更新。
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)
上面的結果集顯示,當我們更新名為'info'的視圖時,基本表也會被更新。
下面是基於視圖'info'創建的名為'info_less'的視圖,當我們更新視圖'info'時,它也會被更新。
mysql> Select * from info_less; +------+-------+-----------+ | Id | Name | Subject | +------+-------+-----------+ | 125 | Raman | Computers | | 130 | Ram | Computers | +------+-------+-----------+ 2 rows in set (0.00 sec)
以上是更新特定視圖中的任何值後,MySQL 是否會更新基底表及其關聯視圖(如果有)中的相同值?的詳細內容。更多資訊請關注PHP中文網其他相關文章!