Any way to hint at primary key without knowing it's name?
Posted on 2007-10-02
Ptjcb was kind enough to supply me with this syntax for hinting at an index:
SELECT * FROM MyTable WITH (INDEX (index_name) where MyField = ?...)
However, I don't know the NAME of the index. It varies from site to site. I do know it's always the primary key for the table, though. Is there any way I can specifiy that?
I found this doc at the MS site:
"If a clustered index exists, INDEX(0) forces a clustered index scan and INDEX(1) forces a clustered index scan or seek. If no clustered index exists, INDEX(0) forces a table scan and INDEX(1) is interpreted as an error. "
Is INDEX(0) or INDEX(1) what I want? Doc I saw elsewhere indicates it forces a table scan, which is the opposite of what I want. Also, in this case, the primary key is clustered, but there is another clustered index also, which the db is already erroneously using to solve my query. (That's the problem I'm trying to solve here...)
THANKS (AGAIN) !