FIX: Delete Operation May Fail to Delete Qualified Rows with a Self Referenced Subquery

This article was previously published under Q274661
This article has been archived. It is offered "as is" and will no longer be updated.
BUG #: 57857 (SQLBUG_70)
A DELETE operation may fail to delete all the selected rows if you use a self-referencing subquery in the WHERE clause. For more information about the nature of the query, see the "More Information" section.
Microsoft has confirmed this to be a problem in SQL Server 7.0. This problem has been corrected in U.S. Service Pack 3 for Microsoft SQL Server 7.0. For more information, click the following article number to view the article in the Microsoft Knowledge Base:
274799 INF: How to Obtain Service Pack 3 for Microsoft SQL Server 7.0 and Microsoft Data Engine (MSDE) 1.0
For more information, contact your primary support provider.

Steps to Reproduce the Problem

  1. Run the following code on a Microsoft SQL Server server that has Service Pack 2 or earlier installed:
    use pubsgodrop table xgocreate table x (id int,pid int)goinsert into x values (1,0)insert into x values (2,1)insert into x values (3,2)godelete from x where pid = (select id from x where pid = 1) or id = 1 or pid = 1go					
  2. Run the following code to check the results:
    select * from x					
    RESULTS: The following output displays when you run the preceding code:

    id          pid         ----------- ----------- 3           2(1 row(s) affected)					

    The expected result is 0 rows.


Article ID: 274661 - Last Review: 10/21/2013 01:54:14 - Revision: 2.1

Microsoft SQL Server 7.0 Standard Edition

  • kbnosurvey kbarchive kbbug kbcodesnippet kbfix KB274661