問題描述
假設我有下表:
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
是常量列.
TaxedPrice
is a derived column, and Tax
is a constant column.
因此,我無法插入或更新其中任何一個.以下第一個查詢將通過,而其他查詢將失敗并顯示錯誤.
Therefore, I can't insert or update any of them. The first following query would pass, whereas the other ones would fail with an error.
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"失敗,因為它包含派生字段或常量字段.
Update or insert of view or function 'Item' failed because it contains a derived or constant field.
有沒有辦法,也許是系統視圖,列出不能更新的視圖列?
Is there a way, maybe with the system views, to list the view columns which must not be updated?
推薦答案
看起來沒有系統視圖保存您要查找的信息.可以通過解析視圖定義或異常處理來找出派生列或常量列...不好,但沒有找到其他方法...
Looks like there is no system view saves information you are looking for. You can find out derived column or constant column by parsing the view definition or by exception handling...not good, but didn't find other ways...
這篇關于如何確定視圖的列是派生的還是常量?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!