当前位置:网站首页>Is not null and in SQL= Difference between null
Is not null and in SQL= Difference between null
2022-06-27 23:36:00 【Full stack programmer webmaster】
Hello everyone , I meet you again , I'm your friend, Quan Jun .
We often meet these two writing methods :IS NOT NULL And !=NULL. Also often meet the database has qualified !=NULL The data of , But the return is an empty collection . actually , It's because we don't understand the difference between them .
By default , Recommended IS NOT NULL Make conditional judgments , because SQL By default WHERE XX!= Null Your judgment will always return to 0 That's ok , But it won't prompt syntax errors .
Why is that ?
SQL Server In the document for Null The comparison of values defines two rules , If in SQL Server 2000 in :
Rule one yes yes ANSISQL(SQL-92) Stipulated Null The comparison results of the values are False, Both Null=Null The value is also False. The other is not allowed to follow ANSISQL standard , namely Null=Null by True.:
For example, data sheet test structure :
Copy code The code is as follows :
ROWNUM DATA
——————-
1 ‘Liu Yang’
2 Null
3 ‘12345’according to ANSI SQL standard , Neither of the following two queries returns any rows :
Query one : SELECT * FROM test WHERE data=NULL Query two : SELECT * FROM test WHERE data<>NULL
Instead of ANSI SQL standard , Inquire about 1 The second line... Will be returned , Inquire about 2 return 1、3 That's ok .
This is because in the SQL in ,NULL Is a unique data type , It is equivalent to having no value 、 It's an unknown number .NULL And 0、 An empty string 、 The spaces are different . ANSI SQL Standard Null The row of values needs to use the following query :
Copy code The code is as follows :
SELECT * FROM test WHERE data IS NULLThis shows that it is not ANSI SQL In the standard data=NULL Equate to data IS NULL,data<>NULL Equate to data IS NOT NULL.
So we should keep in mind : By default, the keyword is used for comparison “is null” and “is not null”.
If you must use != null To make conditional judgments , You need to add this command statement :SET ANSI_NULLS OFF, At this time, the database enters ANSI SQL Non standard mode , You'll find that IS NOT NULL and != null Is equivalent .
The mode switching command is used here SET ANSI_NULLS[ON/OFF].ON Value adoption ANSI SQL Strict standards ,OFF Value is in non-standard compatibility mode . in addition SET ANSI_DEFAULTS [ON/OFF] Command can also realize standard switching , Only this command controls a group that conforms to SQL-92 Standard settings , Among them is Null Value criteria .
By default , Database management program (DB-Library) yes SET ANSI_NULLS by OFF Of . But most of our applications , It's all through ODBC perhaps OLEDB To access the database , As an open and compatible database access program , Maybe it's a compatibility consideration ,SETANSI_NULLS Value is set to ON. Some problems caused by this should be paid attention to . Applications such as stored procedures or custom functions are based on DB-Library Of , By default ,SETANSI_NULLS by OFF, And in such a program , Out of commission SETANSI_NULLS Modify rules in an environment , Only database configuration parameters can be modified .
For example, in the following case : Your application uses ADODB To access the database , use OleDb perhaps ODBC Data provider . For query one : SELECT * FROM test WHERE data=NULL We can directly send commands to get the query result set , You can also put it in a stored procedure . But the results of the two queries are different . If you use the query command directly , Do not return any rows ; And if you access a stored procedure , Back to page 2 Row data .
Last , We declare once again : By default, the database , do SQL Use keywords when comparing conditional queries “is null” and “is not null”.
Publisher : Full stack programmer stack length , Reprint please indicate the source :https://javaforall.cn/133155.html Link to the original text :https://javaforall.cn
边栏推荐
- Const keyword and its function (usage), detailed explanation of C language const
- matlab axis坐标轴相关设置详解
- Structure de stockage des graphiques
- pytorch实现kaggle猫狗识别
- [tinyriscv verilator] branch transplanted to Da Vinci development board of punctual atom
- MySQL十八:写语句的执行过程
- 支持删除,更新任意结点的优先级队列
- [network] common request methods
- 【蓝桥杯集训100题】scratch数字计算 蓝桥杯scratch比赛专项预测编程题 集训模拟练习题第16题
- 【IDEA】IDEA 格式化 代码技巧 idea 格式化 会加 <p> 标签
猜你喜欢
![[Blue Bridge Cup training 100 questions] scratch digital calculation Blue Bridge Cup competition special prediction programming question collective training simulation exercise question No. 16](/img/7c/d4ea8747ce45fd2eb59a8f968653db.png)
[Blue Bridge Cup training 100 questions] scratch digital calculation Blue Bridge Cup competition special prediction programming question collective training simulation exercise question No. 16

发射,接收天线方向图

因美纳陷数据泄露“丑闻”:我国基因数据安全能交给美企吗?

SQL Server 2016详细安装教程(附注册码和资源)

【蓝桥杯集训100题】scratch数字计算 蓝桥杯scratch比赛专项预测编程题 集训模拟练习题第16题

webService

seata

Ice cream or snow "high"?

实践torch.fx:基于Pytorch的模型优化量化神器

Discuz small fish game wind shadow legend business gbk+utf8 version template /dz game website template
随机推荐
Detect objects and transfer images through mqtt
虽然TCGA数据库有33种癌症
go日志包 log的使用
Netease cloud lost its "feelings" card
NDSS 2022 接收的列表
To build a "strong core" in Nansha, the first IC Nansha conference was held in Nansha
发射,接收天线方向图
Working at home is more tiring than going to work at the company?
Ice cream or snow "high"?
本机部署一个MongoDB单节点服务器,并启用auth验证、开启oplog
pytorch 入门指南
Summary of solutions to cross system data consistency problems
Cornernet由浅入深理解
【PCL自学:PCLPlotter】PCLPlotter绘制数据分析图
SQL Server 2016详细安装教程(附注册码和资源)
Teach you how to transplant tinyriscv to FPGA
Typora 1.2.5等版本下载
Prediction of benign / malignant breast tumors (logistic regression classifier)
fiddler 监听不到接口怎么办
解决新版chrome跨域问题:cookie丢失以及samesite属性问题「建议收藏」