So, here is the test query you could play with:
select top 10 * into #tmp FROM A
delete from #tmp WHERE xxx_id in (select xxx_id FROM B)
Actually, all these 10 records are deleted. The question is why are these 10 records deleted?
Note: xxx_id
is one column in table A
only, it doesn't exist in table B
. But the delete statement "works" anyway.
Here's a demonstration of this behaviour: http://sqlfiddle.com/#!6/963f9/1/1
Update
I found the answer in MSDN: http://social.msdn.microsoft.com/Forums/en-US/418722dc-a7bf-44c5-a2f6-e8d1cd00dbdc/in-clause-ignores-error-in-subquery-possible-bug?forum=transactsql
Actually, the MSSQL tried to blind the xxx_id
to table B
in subquery, if not found, it tries to blind it to table A
. So, the query equals:
delete from #tmp WHERE xxx_id = xxx_id
and all data was deleted.