是的,这非常简单
CREATE TABLE dbo.FooTable
(
SomeId INT,
AnotherId INT,
Filler CHAR(8000)
);
go
CREATE VIEW dbo.FooView
WITH SCHEMABINDING
AS
SELECT SomeId,
AnotherId,
Filler
FROM dbo.FooTable
GO
CREATE UNIQUE CLUSTERED INDEX IX_Foo1
ON dbo.FooView(SomeId, AnotherId)
CREATE NONCLUSTERED INDEX IX_Foo2
ON dbo.FooView(SomeId)
GO
SELECT SomeId
FROM dbo.FooView WITH (noexpand) --No hint non clustered index chosen automatically
SELECT *
FROM dbo.FooView WITH (noexpand) --No hint clustered index chosen automatically
SELECT *
FROM dbo.FooView WITH (noexpand, INDEX = IX_Foo2) --With hint nonclustered index forced
执行计划
(请注意,使用提示强制索引会导致比将选择留给优化器更昂贵的计划)