比方說,我有如下表:如何確定視圖的列是派生的還是常量?
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)
這裏是返回的錯誤信息:
更新或視圖或函數「項」插入失敗,因爲它包含派生或恆定的場。
有沒有一種方法,也許有系統視圖,列出不得更新的視圖列?
不知道。我希望'sys_columns'中的'is_computed'能夠顯示這一點,但似乎並不適用於視圖,我在['COLUMNPROPERTY'](http://msdn.microsoft.com/en- us/library/ms174968.aspx)。 – 2013-03-06 14:55:18
'is_computed'也是我的第一個猜測,但[Microsoft的定義](http://msdn.microsoft.com/zh-cn/library/ms191250(v = SQL.105).aspx)是: '計算列是從可以使用同一個表中的其他列的表達式計算出來的。「在這種情況下情況並非如此,因爲視圖的列使用基礎表中的列,而不是視圖本身。 – madprog 2013-03-06 15:08:03