我正在创建一个视图来向用户显示他/她的数据,但我也希望用户能够在这些视图中的某些字段中进行更改。视图中所做的更改是否也反映在基表中?
另外,我能否更新由多个基表组成的视图?
我正在创建一个视图来向用户显示他/她的数据,但我也希望用户能够在这些视图中的某些字段中进行更改。视图中所做的更改是否也反映在基表中?
另外,我能否更新由多个基表组成的视图?
如可更新和可插入视图中所述:
一些视图是可更新的。也就是说,您可以在诸如
UPDATE
、DELETE
、等语句中使用它们INSERT
来更新基础表的内容。要使视图可更新,视图中的行与基础表中的行之间必须存在一对一的关系。还有某些其他构造使视图不可更新。更具体地说,如果视图包含以下任何内容,则它是不可更新的:
DISTINCT
GROUP BY
HAVING
选择列表中的子查询
某些联接(请参阅本节后面的附加联接讨论)
FROM
子句中的不可更新视图子句中的子查询
WHERE
引用子句中的FROM
表Refers only to literal values (in this case, there is no underlying table to update)
Uses
ALGORITHM = TEMPTABLE
(use of a temporary table always makes a view nonupdatable)Multiple references to any column of a base table.
[ deletia ]
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 aUNION
). Also, only a single table in the view definition can be updated, so theSET
clause must name only columns from one of the tables in the view. Views that useUNION ALL
are not permitted even though they might be theoretically updatable, because the implementation uses temporary tables to process them.