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

Article translations Article translations
Article ID: 274661 - View products that this article applies to.
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)
Expand all | Collapse all

On This Page


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 pubs
    drop table x
    create table x (id int,pid int)
    insert into x values (1,0)
    insert into x values (2,1)
    insert into x values (3,2)
    delete from x where pid = (select id from x where pid = 1) or id = 1 or pid = 1
  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: October 21, 2013 - Revision: 2.1
  • Microsoft SQL Server 7.0 Standard Edition
kbnosurvey kbarchive kbbug kbcodesnippet kbfix KB274661

Contact us for more help

Contact us for more help
Connect with Answer Desk for expert help.
Get more support from