• <bdo id='OEkkn'></bdo><ul id='OEkkn'></ul>
      1. <tfoot id='OEkkn'></tfoot>

        <small id='OEkkn'></small><noframes id='OEkkn'>

        <legend id='OEkkn'><style id='OEkkn'><dir id='OEkkn'><q id='OEkkn'></q></dir></style></legend>

        <i id='OEkkn'><tr id='OEkkn'><dt id='OEkkn'><q id='OEkkn'><span id='OEkkn'><b id='OEkkn'><form id='OEkkn'><ins id='OEkkn'></ins><ul id='OEkkn'></ul><sub id='OEkkn'></sub></form><legend id='OEkkn'></legend><bdo id='OEkkn'><pre id='OEkkn'><center id='OEkkn'></center></pre></bdo></b><th id='OEkkn'></th></span></q></dt></tr></i><div id='OEkkn'><tfoot id='OEkkn'></tfoot><dl id='OEkkn'><fieldset id='OEkkn'></fieldset></dl></div>

      2. 在 MySQL 中更新视图

        时间:2024-04-15

        • <i id='2gZZa'><tr id='2gZZa'><dt id='2gZZa'><q id='2gZZa'><span id='2gZZa'><b id='2gZZa'><form id='2gZZa'><ins id='2gZZa'></ins><ul id='2gZZa'></ul><sub id='2gZZa'></sub></form><legend id='2gZZa'></legend><bdo id='2gZZa'><pre id='2gZZa'><center id='2gZZa'></center></pre></bdo></b><th id='2gZZa'></th></span></q></dt></tr></i><div id='2gZZa'><tfoot id='2gZZa'></tfoot><dl id='2gZZa'><fieldset id='2gZZa'></fieldset></dl></div>
            <tbody id='2gZZa'></tbody>
          • <bdo id='2gZZa'></bdo><ul id='2gZZa'></ul>

                <small id='2gZZa'></small><noframes id='2gZZa'>

              1. <legend id='2gZZa'><style id='2gZZa'><dir id='2gZZa'><q id='2gZZa'></q></dir></style></legend>

                  <tfoot id='2gZZa'></tfoot>

                  本文介绍了在 MySQL 中更新视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在创建一个视图来向用户显示他/她的数据,但我也希望用户能够在这些视图中的某些字段中进行更改.视图中所做的更改是否也反映在基表中?

                  I am creating a view to show the user his/her data, but I also want the user to be able to make changes in some of the fields in those views. Are the changes made in a view reflected in the base table as well?

                  另外,我能否更新由多个基表组成的视图?

                  Also, would I be able to update a view that is made up of more than one base table?

                  推荐答案

                  如 可更新和可插入的视图:

                  某些视图是可更新的.也就是说,您可以在诸如 UPDATEDELETEINSERT 更新底层表的内容.要使视图可更新,视图中的行与基础表中的行之间必须存在一对一的关系.还有某些其他构造使视图不可更新.更具体地说,如果视图包含以下任何一项,则该视图不可更新:

                  Some views are updatable. That is, you can use them in statements such as UPDATE, DELETE, or INSERT to update the contents of the underlying table. For a view to be updatable, there must be a one-to-one relationship between the rows in the view and the rows in the underlying table. There are also certain other constructs that make a view nonupdatable. To be more specific, a view is not updatable if it contains any of the following:

                  • 聚合函数(SUM(), MIN(), MAX(), COUNT(),等等)

                  DISTINCT

                  GROUP BY

                  HAVING

                  UNIONUNION ALL

                  选择列表中的子查询

                  某些连接(请参阅本节后面的其他连接讨论)

                  Certain joins (see additional join discussion later in this section)

                  FROM 子句中的不可更新视图

                  Nonupdatable view in the FROM clause

                  WHERE 子句中的子查询引用了 FROM 子句中的表

                  A subquery in the WHERE clause that refers to a table in the FROM clause

                  仅指字面值(在本例中,没有要更新的基础表)

                  Refers only to literal values (in this case, there is no underlying table to update)

                  使用ALGORITHM = TEMPTABLE(使用临时表总是使视图不可更新)

                  Uses ALGORITHM = TEMPTABLE (use of a temporary table always makes a view nonupdatable)

                  多次引用基表的任何列.

                  Multiple references to any column of a base table.

                  [删除]

                  多表视图有时可能是可更新的,假设它可以用 MERGE 算法进行处理.为此,视图必须使用内连接(不是外连接或 联合).此外,视图定义中只能更新单个表,因此 SET 子句必须仅命名视图中一个表中的列.即使使用 UNION ALL 的视图也是不允许的它们理论上可能是可更新的,因为实现使用临时表来处理它们.

                  It is sometimes possible for a multiple-table view to be updatable, assuming that it can be processed with the MERGE algorithm. For this to work, the view must use an inner join (not an outer join or a UNION). Also, only a single table in the view definition can be updated, so the SET clause must name only columns from one of the tables in the view. Views that use UNION ALL are not permitted even though they might be theoretically updatable, because the implementation uses temporary tables to process them.

                  这篇关于在 MySQL 中更新视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:创建一个带有 num_rows 列的视图 - MySQL 下一篇:mySQL 中的交叉表视图?

                  相关文章

                • <legend id='mSuBG'><style id='mSuBG'><dir id='mSuBG'><q id='mSuBG'></q></dir></style></legend>
                  1. <i id='mSuBG'><tr id='mSuBG'><dt id='mSuBG'><q id='mSuBG'><span id='mSuBG'><b id='mSuBG'><form id='mSuBG'><ins id='mSuBG'></ins><ul id='mSuBG'></ul><sub id='mSuBG'></sub></form><legend id='mSuBG'></legend><bdo id='mSuBG'><pre id='mSuBG'><center id='mSuBG'></center></pre></bdo></b><th id='mSuBG'></th></span></q></dt></tr></i><div id='mSuBG'><tfoot id='mSuBG'></tfoot><dl id='mSuBG'><fieldset id='mSuBG'></fieldset></dl></div>
                      <bdo id='mSuBG'></bdo><ul id='mSuBG'></ul>
                  2. <tfoot id='mSuBG'></tfoot>

                      <small id='mSuBG'></small><noframes id='mSuBG'>