I have the following example code:
create table #tempmembers (
memberid int
)
update Members set
Member_EMail = NULL
where Member_ID in (select member_id from #tempmembers)
The subselect contains an error, since #tempmembes
does not contain a column开发者_如何转开发 named member_id
, but the sql statements run WITHOUT any errors and update no rows.
If I then add just ONE row to #tempmembers
:
create table #tempmembers (
memberid int
)
insert into #tempmembers select 1
update Members set
Member_EMail = NULL
where Member_ID in (select member_id from #tempmembers)
it still runs without any errors - but this time ALL records in Members will be affected.
Why does the SQL statement not fail completely? And if the failing subselect is evaluated to NULL - should updating all rows in Members
not only occur if it had been:
update Members set
Member_EMail = NULL
where Member_ID not in (select member_id from #tempmembers)
It's inheriting member_id
from the outer query so is equivalent to:
...
(select Members.member_id from #tempmembers)
This will fail as expected:
...
(select #tempmembers.member_id from #tempmembers)
精彩评论