“从表中删除 NULL = NULL”是什么意思?方法?
delete from table where NULL = NULL
是什么意思?
What does delete from table where NULL = NULL
mean?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
delete from table where NULL = NULL
是什么意思?
What does delete from table where NULL = NULL
mean?
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(8)
这意味着不要删除任何内容,因为 NULL 永远不等于任何内容。或者它的意思可能是“不要删除任何东西,除非用户的 DBMS 真的很糟糕,在这种情况下,出于恶意将其全部删除”。
但说真的,这种构造通常在程序生成 WHERE 子句时出现 - 而不是创建“不执行任何操作”的特殊情况,有时生成一个导致数据库不执行任何操作的 WHERE 子句会更简单。不过,我通常看到“WHERE 0 = 1”,这不太含糊。
It means don't delete anything, because NULL is never equal to anything. Or maybe it means "don't delete anything unless the user's DBMS really sucks, in which case delete it all out of spite".
Seriously though, that kind of construct usually comes about when a WHERE clause is procedurally generated -- rather than creating a special case for "do nothing", sometimes it's simpler just to generate a WHERE clause that causes the database to do nothing. I've usually seen "WHERE 0 = 1" though, which is less ambiguous.
在SQL中,有3个逻辑值,分别是TRUE、FALSE和UNKNOWN。当我们将 null 与 null 进行比较时,使用 null=null,该操作将返回 UNKNOWN。此外,在 WHERE 子句中,所有 UNKNOWN 值都被过滤掉。因此查询不执行任何操作。
In SQL, there are three logical values, namely TRUE, FALSE, and UNKNOWN. when we compare null to null, using null=null, the operation will return UNKNOWN. Moreover,In the WHERE clause all UNKNOWN values are filtered out.Hence the query does nothing.
它惩罚那些在数据库中将 ANSI_NULLS 设置为关闭的人:)
It punishes people who have ANSI_NULLS set to off in their database :)
由于 NULL 不等于 NULL,因此该语句不会执行任何操作。它等于:
Since NULL does not equal NULL, this statement will do nothing. It equals:
概括一下:
意思是,如果条件计算结果为 null,则 MySql 会认为该条件为 false,因此从 NULL = NULL 的表中删除实际上不会删除任何内容。
Codd 指出,NULL 是一种特殊的野兽
Recap:
Meaning, if a condition evaluates to null it is considered false by MySql so
delete from table where NULL = NULL
will in fact delete nothing.NULL is a special beast as noted by Codd
我想这取决于数据库,但据我所知,它不应该实现任何目标,因为 NULL 永远不等于 NULL,至少在数据库理论中是这样。
I imagine it depends on the database, but to my knowledge, it shouldn't achieve anything, as NULL is never equal to NULL, at least in db theory.
此 SQL 命令不会影响任何行。
Not a single row is affected by this SQL command.
这不会从表中删除任何内容。
NULL 不等于 NULL。
现在
将删除表中的所有行。
That will delete nothing from the table.
NULL does not equal NULL.
Now
would delete all rows from the table.