Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Why table scan?
Message
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Why table scan?
Environment versions
SQL Server:
SQL Server 2000
Miscellaneous
Thread ID:
01293823
Message ID:
01293823
Views:
64
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.
The version of SQL Server is obsolete. I test this on both 2000 and 2005, that is why I think I'm missing something.
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
Against Stupidity the Gods themselves Contend in Vain - Johann Christoph Friedrich von Schiller
The only thing normal about database guys is their tables.
Next
Reply
Map
View

Click here to load this message in the networking platform