【发布时间】:2013-02-21 09:51:05
【问题描述】:
假设我有下表:
create table t_Item (
ItemID int not null identity(1,1) constraint PK_Item primary key,
Description varchar(256) not null,
Price decimal(10,2) not null
)
还有以下观点:
create view Item as
select ItemID
,Description
,Price
,1.09 Tax
,Price * 1.09 TaxedPrice
from t_Item
TaxedPrice 是派生列,Tax 是常量列。
因此,我无法插入或更新其中任何一个。以下第一个查询将通过,而其他查询将失败并出现错误。
insert into Item (Description, Price) values ('Test item', 14.00)
insert into Item (Description, Price, TaxedPrice) values ('Test item', 14.00, 15.26)
insert into Item (Description, Price, Tax) values ('Test item', 14.00, 1.09)
这里是返回的错误信息:
视图或函数“Item”的更新或插入失败,因为它包含派生或常量字段。
有没有办法(可能是系统视图)列出不能更新的视图列?
【问题讨论】:
-
不知道。我原以为
sys.columns中的is_computed会显示这一点,但似乎没有意见,我也没有在COLUMNPROPERTY中看到任何内容。 -
is_computed也是我的第一个猜测,但Microsoft's definition 是:A computed column is computed from an expression that can use other columns in the same table.情况并非如此,因为视图的列使用基础表中的列,而不是来自查看自己。
标签: sql-server view system-views