小编Dmi*_*mov的帖子

无法针对具有屏蔽列的表创建索引视图

我正在尝试在引用带有屏蔽列的表(SQL Server 2016)的视图上创建索引。屏蔽列不是该表中唯一的列,并且未在视图中使用。

create unique clustered index [IX_Name]
on dbo.vw_ViewName(SomeUniqueId)
Run Code Online (Sandbox Code Playgroud)

我收到此错误:

无法创建视图“dbo.vw_ViewName”上的索引,因为该视图正在引用带有屏蔽列的表“dbo.TableName”。

在另一个未启用屏蔽的环境中,索引创建成功。

我浏览了大约四页的 Google 结果,但没有找到任何合理的错误描述。我很感激任何关于错误的知识转移以及为什么不可能创建这样的索引。

这是一些重现问题的 SQL:

drop view if exists dbo.vw_Aggregate
drop table if exists dbo.MainTable, dbo.SecondaryTable
go

create table dbo.MainTable
(
    MainTableId uniqueidentifier primary key,
    SomeExternalId uniqueidentifier,
    SecondaryTableId uniqueidentifier
)
go

create table dbo.SecondaryTable
(
    SecondaryTableId uniqueidentifier primary key,
    CreatedOn datetime,
    Amount decimal(19, 8),
    -- the below column produces error,
    -- if commented out - there is no error
    [Description] nvarchar(max) masked with (function = 'default()'),
    Dummy …
Run Code Online (Sandbox Code Playgroud)

sql-server materialized-view sql-server-2016 data-masking dynamic-data-masking

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