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
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
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)