本题考查SQL语句中空值的查询方法。其中is not null表示没有空值,is null表示有空值,故正确答案为D
在给定的选项中,要查询所有 `t1` 表中城市名为空的记录,正确的 SQL 语句是选项 D。
选项分析:
A: `select * from t1 where city_name not null;`
- 这个语句是错误的,因为 SQL 中判断是否为空值应该使用 `IS NULL` 或 `IS NOT NULL`,而不是直接使用 `not null`。
B: `select * from t1 where city_name is not null;`
- 这个语句用于查询城市名不为空的记录,与问题要求相反。
C: `select * from t1 where city_name null;`
- 这个语句是错误的,因为 `null` 前面缺少 `IS` 关键字。
D: `select * from t1 where city_name is null;`
- 这个语句是正确的,用于查询城市名为空的记录。
因此,正确答案是 D: `select * from t1 where city_name is null;`。