Odd select behavior on SQL Server 7

Status
Not open for further replies.

Coleman

Ars Legatus Legionis
16,790
Subscriptor
Hi all,

I've got an oddball problem that I can't figure out and haven't ever seen before.

I have 2 tables, one generates a primary key which acts as a foreign key on the other.

Something started happening recently where the data on the second table has ceased being accessible through the use of the foreign key on the second table AFTER a certain value. But it's still visible if I do a broader WHERE clause. i.e.:

SELECT * FROM TABLE B WHERE ID > 3700

returns
ID
--
3701
3702
3703
3704
3705

this works:
SELECT * FROM TABLE B WHERE ID = 3703

this doesn't:
SELECT * FROM TABLE B WHERE ID = 3704

In fact, I can't retrieve through the fk for any records after that value. It's real weird. I can see it if I make the where clause such that I catch it in a blanket search, but it fails on the specific ID. Any ideas?

Thanks,
J
 

Coleman

Ars Legatus Legionis
16,790
Subscriptor
I highly doubt it's hardware. It's our dev box, but it's got 2GB memory and it's a dual P3 Dell server. And the table has not more then 5000 rows.

No errors. Just 0 rows returned. It's very puzzling.
The fk field is a int field, same as the pk field is in the other table. Generated by SQL Server as an identity field.

The only thing I managed to come up with is that there is another field in the fk table which is serving as the pk for that table. I noticed when I checked the execution plan for the single record query that one of the steps is a clustered index lookup. That appears to be the only index lookup I believe. The problem is that the clustered index is on the pk field, not the fk field, so I wonder if maybe it's using the wrong index to do data retrieval? I guess I can kill the pk field and see if a table scan happens instead, but before I do, if anyone has any other ideas, please to share. :)
-J
 

raphael_as

Ars Tribunus Angusticlavius
6,773
Subscriptor++
The only thing I managed to come up with is that there is another field in the fk table which is serving as the pk for that table. I noticed when I checked the execution plan for the single record query that one of the steps is a clustered index lookup. That appears to be the only index lookup I believe. The problem is that the clustered index is on the pk field, not the fk field, so I wonder if maybe it's using the wrong index to do data retrieval? I guess I can kill the pk field and see if a table scan happens instead, but before I do, if anyone has any other ideas, please to share.

I wonder if you dont have 2 ID fields on your table? If both the tables own PK field and your FK field are generated as ID fields in SQL could this cause the problem?
 
Status
Not open for further replies.