I don't get it.
Maybe I missing something very obvious or I didn't read this part of BOL, but almost same queries give me different results in execution plan.
In one table I have PK clustered, in other I have regular index. When I execute first query execution plan shows INDEX SEEK when I execute second one execution plan shows TABLE SCAN.
Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
Microsoft MVP VFP
Maybe I missing something very obvious or I didn't read this part of BOL, but almost same queries give me different results in execution plan.
In one table I have PK clustered, in other I have regular index. When I execute first query execution plan shows INDEX SEEK when I execute second one execution plan shows TABLE SCAN.
Code:
CREATE DATABASE Test
GO
USE Test
GO
Create TABLE Test1 (Fld1 int, Fld2 varchar(200)
CONSTRAINT PK_Tets1
PRIMARY KEY CLUSTERED (Fld1)
)
Create TABLE Test2 (Fld1 int, Fld2 int, Fld3 int, Fld4 varchar(200))
CREATE INDEX IX_Test2 ON Test2 (Fld1, Fld2, Fld3)
GO
--- This gives me INDEX SEEK for Test2
SELECT Test1.*
FROM Test1
LEFT JOIN Test2 ON Test1.Fld1 = Test2.Fld1 AND Test2.Fld2 = 14 AND Fld3 = 1
WHERE Test1.Fld1 > 0
--- This gives me TABLE SCAN for Test2
SELECT * -- Fields from both tables.
FROM Test1
LEFT JOIN Test2 ON Test1.Fld1 = Test2.Fld1 AND Test2.Fld2 = 14 AND Fld3 = 1
WHERE Test1.Fld1 > 0
GO
USE Master
DROP DATABASE Test
Borislav Borissov
VFP9 SP2, SQL Server 2000/2005.
Microsoft MVP VFP