Possible Duplicate:
sql server 2008 management studio not checking the syntax of my query
I ran across an issue today where a subquery was bad and the result was all rows from the parent table were deleted.
TableA
ID,
Text,
GUID
TableB
ID,
TableAID,
Text
delete from TableB
where id in (
select TableAID
from TableA
where GUID = 'fdjkhflafdhf'
)
If you run the subquery by itself you get an error since the column (TableAID) doesn't exist in Table A. If you run the full query - it deletes all records from table B without an error.
I also tried the following queries which removed 0 records (expected)
delete from TableB where id in (null)
delete from TableB where id in (select null)
Can someone explain to my why this is occurring when the query is malformed? Why does it seem to evaluate to true?
Note: This was tested on SQL Server 2008 R2