我有以下版本的 SQL Server:
Microsoft SQL Server 2014 (SP3) (KB4022619) - Windows NT 6.3 上的 12.0.6024.0 (X64) 企业版(64 位)(内部版本 9600:)(管理程序)
我创建了以下视图
CREATE VIEW [dbo].[vwGroupsOfficesDependencies]
WITH SCHEMABINDING
AS
SELECT GC.IdGroup, COUNT_BIG(*) AS countBig, OD.IdOffice
FROM dbo.Group AS GC INNER JOIN
dbo.GroupDependencies AS GD ON GC.IdGroup = GD.IdGroup INNER JOIN
dbo.OfficeDependencies AS OD ON OD.IdDependency = GD.IdDependency INNER JOIN
dbo.Dependencies AS D ON D.IdDependency = GD.IdDependency
WHERE (D.Active = 1)
GROUP BY GC.IdGroup, OD.IdOffice
Run Code Online (Sandbox Code Playgroud)
然后我创建了聚集索引
CREATE UNIQUE CLUSTERED INDEX [IX_vwGroupsOfficesDependencies_IdOficeIdGroup] ON [dbo].[vwGroupsOfficesDependencies]
( …Run Code Online (Sandbox Code Playgroud) sql-server optimization hints materialized-view sql-server-2014