SqlServer-- NULL空值处理

 数据库中,一个列如果没有指定值,那么值就为null,数据库中的null表示“不知道”,而不是表示没有。因此select null+1结果是null,因为“不知道”加1的结果还是“不知道”。
select * from score where english = null ;
select * from score where english != null ;都没有任何返回结果,因为数据库也“不知道”。
SQL中使用is null、is not null来进行空值判断:

select * from score where english is null ; select * from score where english is not null ;
ISNULL ( check_expression , replacement_value )

 

select * from TblStudent

--查询所有年龄是null的同学信息

--null值无法使用=或<>来进行比较

--unknown

--判断null值必须使用is null或者is not null

select * from TblStudent where tsage is null

select * from TblStudent where tsage=null

 

--查询所有年龄不是null的同学

select * from TblStudent where tsage<>null

select * from TblStudent where tsage is not null

select * from TblStudent where tsage=25

select * from TblStudent where tsage<>25

 

--任何值与null进行计算,得到的结果还是null

select 2000+null

 

posted @   hao_1234_1234  阅读(9944)  评论(0编辑  收藏  举报
编辑推荐:
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示