FIX: Optimizer Chooses Table Scan Instead of Index Seek for Simple SELECT Involving @@identity (246177)



The information in this article applies to:

  • Microsoft SQL Server 7.0

This article was previously published under Q246177
BUG #: 55626 (SQLBUG_70)

SYMPTOMS

When you include @@IDENTITY in the WHERE clause of a SELECT statement, the Query Optimizer chooses to perform a table scan rather than using the appropriate index.

CAUSE

@@IDENTITY is not being recognized as a run-time constant.

WORKAROUND

Declare a variable, set it equal to @@IDENTITY, and then use the variable in the SELECT statement.

STATUS

Microsoft has confirmed this to be a problem in SQL Server 7.0. This problem has been corrected in U.S. Service Pack 2 for Microsoft SQL Server 7.0. For more information, click the following article number to view the article in the Microsoft Knowledge Base:

254561 INF: How to Obtain Service Pack 2 for Microsoft SQL Server 7.0 and Microsoft Data Engine (MSDE) 1.0

For more information, contact your primary support provider.

Modification Type:MajorLast Reviewed:3/14/2006
Keywords:kbBug kbfix KB246177