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 是否会更新基表及其关联视图(如果有)中的相同值?的详细内容。