gpt4 book ai didi

sql - 如何根据 NULL 条件删除 SQL 中的一行

转载 作者:行者123 更新时间:2023-12-04 20:48:54 25 4
gpt4 key购买 nike

我刚开始学习SQL;我已经创建了一个表。学习了插入命令并在 2 行中插入值。但是我在第三个中插入了空值。

现在我想删除有 2 列但没有值的第三行。

我正在使用以下查询:

delete employee where city=null;

它似乎不起作用!

最佳答案

根据 SQL 92 标准的许多具有空值的逻辑运算,例如

   > null
= null
and null
or null
not null

应始终返回 null(并且永远不会为真)。一些 DBMS(例如 Oracle)严格遵循此规则,一些(MS SQL)可以具有 null = null 的模式返回 true,不需要 null。为了与 SQL 92 以及(几乎)所有 DBMS 兼容,您应该使用 is nullis not null标准比较,在你的情况下
  delete from employee 
where city is null -- <- Standard comparison

关于sql - 如何根据 NULL 条件删除 SQL 中的一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21988661/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com