更新索引视图的基础表但该列不在视图中

Updating underlying tables of indexed view but the column is not present in the view

假设我有两个 tables,Country 和 City。

Country(id, fname, president_name)
City(id, cname, country_id_fk, mayor_name)

城市 table 对外键依赖于国家 table。假设我在 table 上创建了一个索引视图,如下所示:

CREATE VIEW CountryCity
WITH SCHEMABINDING
AS
    SELECT Country.fname, City.cname
    FROM Country INNER JOIN City
    ON Country.id = City.country_id_fk;
GO

并在该视图上创建一个唯一的聚簇索引

CREATE UNIQUE CLUSTERED INDEX ucidx_cc
ON CountryCity(cname, fname);
GO

请注意,我在视图中没有 president_name。如果我更新国家 table 中的 president_name,是否会影响 CountryCity 视图。

我想说的是,在 Country table 更新期间会不会出现性能问题,因为我们对 table 有一个索引视图?

您基本上可以拥有包含特定列的索引。当您更新其他列时,如果它们不包含在索引中,则不会应用维护其数据的操作。

此外,SQL 引擎能够为每个 table 维护大量索引,因此无需担心如此简单的设计。