小编mad*_*rog的帖子

如何确定视图的列是派生还是常量?

假设我有下表:

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
)
Run Code Online (Sandbox Code Playgroud)

以及以下观点:

create view Item as
  select ItemID
        ,Description
        ,Price
        ,1.09 Tax
        ,Price * 1.09 TaxedPrice
    from t_Item
Run Code Online (Sandbox Code Playgroud)

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)
Run Code Online (Sandbox Code Playgroud)

这是返回的错误消息:

更新或插入视图或功能"项目"失败,因为它包含派生或常量字段.

有没有办法,可能有系统视图,列出不能更新的视图列?

sql-server view system-views

9
推荐指数
1
解决办法
2万
查看次数

标签 统计

sql-server ×1

system-views ×1

view ×1