可能重复:
sql server 2008 management studio not checking the syntax of my query
T-SQL Deletes all rows from a table when subquery is malformed
请参阅以下查询:
select * from tablea where reference in (
select reference from tableb)表中不存在列reference,因此我希望看到一个错误,但是返回表a中的所有行。
为什么表A中的所有行都会返回?
发布于 2012-01-23 16:58:08
在子查询select reference from tableb中,您可以看到来自高级查询的所有列,因此您的条件实际上类似于"where 1= 1“。
这是一个很好的建议的原因之一:“如果您从多个表中选择一个别名,请给每个表一个别名”。例如,在您的例子中:
select a.* from tablea a where a.reference in (
select b.reference from tableb b)这样,您就可以得到预期的编译错误。
https://stackoverflow.com/questions/8975343
复制相似问题