I have an indexed view, but when I run queries in that view, the index that is built on the view is not applied, and the query is executed without an index. Below is my dummy script: Tables + View + Pointer in view
CREATE TABLE P_Test ( [PID] INT IDENTITY, [TID] INT, [StatusID] INT ) CREATE TABLE T_Test ( [TID] INT IDENTITY, [FID] INT, ) CREATE TABLE F_Test ( [FID] INT IDENTITY, [StatusID] INT ) GO INSERT INTO F_Test SELECT TOP 1000 ABS(CAST(NEWID() AS BINARY(6)) %10)
Now, when I run the following queries, the index [PK_TestView] is not applied:
SELECT PStatusID , FStatusID , PID FROM [TestView] SELECT PStatusID , FStatusID , PID FROM [TestView] WHERE [PStatusID]=1 SELECT COUNT(PStatusID) FROM [TestView] WHERE [PStatusID]=1
Can you help me fix this?
source share