惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Vercel News
Vercel News
Recorded Future
Recorded Future
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The GitHub Blog
The GitHub Blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
Google DeepMind News
Google DeepMind News
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Microsoft Azure Blog
Microsoft Azure Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
M
MIT News - Artificial intelligence
云风的 BLOG
云风的 BLOG
Y
Y Combinator Blog
N
News | PayPal Newsroom
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Help Net Security
Help Net Security
博客园 - Franky
SecWiki News
SecWiki News
Recent Announcements
Recent Announcements
T
Troy Hunt's Blog
The Register - Security
The Register - Security
The Last Watchdog
The Last Watchdog
Webroot Blog
Webroot Blog
S
Security Affairs
博客园 - 司徒正美
S
Schneier on Security
I
InfoQ
博客园_首页
www.infosecurity-magazine.com
www.infosecurity-magazine.com
T
Threat Research - Cisco Blogs
Forbes - Security
Forbes - Security
腾讯CDC
N
Netflix TechBlog - Medium
N
News and Events Feed by Topic
Cloudbric
Cloudbric
T
The Exploit Database - CXSecurity.com
P
Proofpoint News Feed
A
About on SuperTechFans
Engineering at Meta
Engineering at Meta
Recent Commits to openclaw:main
Recent Commits to openclaw:main
B
Blog
V
Vulnerabilities – Threatpost
C
Check Point Blog
Google DeepMind News
Google DeepMind News
Google Online Security Blog
Google Online Security Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Hacker News - Newest:
Hacker News - Newest: "LLM"
C
Cisco Blogs
Schneier on Security
Schneier on Security
O
OpenAI News
K
Kaspersky official blog

博客园 - 柏放

检测移动设备横竖屏 [转]一句css代码让你的网站变灰,一起悼念地震中逝去的生命! MYSQL命令行常用操作 MySQL数据库导入导出详解[转发] 国外达人收集的Cheet Sheet PHP学习:字符串操作和正则表达式 PHP学习:数组 PHP学习:文件操作 SQL Server:获得用户最新或前n条订单的几种SQL语句 SQL Server:APPLY表运算符 SQL Server:查询当前服务器有多少连接请求 js倒计时 SQL Server:在Management Studio中使用Web浏览器 SQL Server:获得表的元数据 - SET FMTONLY ON 排序:插入排序及希尔排序 SQL Server:把CSV文件导入到SQL Server表中 SQL Server:使用一个语句块插入多条记录 SQL Server:在事务中回滚TRUNCATE操作 Google Map API学习记录
SQL Server:关于Null的一些事
柏放 · 2011-08-04 · via 博客园 - 柏放

    我们设计表时,在字段是否允许Null值这个问题上,有时会争论一番。数据库牛人Kalen Delaney则给了一下建议
    1,永远不要在用户表中允许NULL值
    2,在用户表定义中包含一个NOT NULL限制
    3,不要依赖数据库属性来控制NULL值的行为

    对于第一点,我们反向说,如果允许NULL,会给我们带来什么影响。
        1,SQL 在每条记录中都设置了一个特殊的bitmap来显示哪些允许空值的列上存储的真的是空值。如果是NULL,在访问每一行的时候SQL Server都必须对这个bitmap进行解码。
        2,允许NULL还增加了应用程序代码的复杂度,总的添加一些特殊的逻辑来处理这个NULL值,这常常会导致bug。

    第二点,在包含不允许NULL的列上,要加入一些默认值,如果不允许NULL,但是还没有加默认值,在没有显示列插入的话,就会造成INSERT的失败,SQL Server默认在INSERT中,对没有显示的列做NULL插入。

    最后一点,主要涉及到于NULL值的比较。在我们印象中,是用IS NULL,IS NOT NULL比较呢,还是用=,<>比较呢。这取决于数据库选项ANSI NULLS,我们不可能更改数据库选项(我们大部分不是DBA),但是我们可以使用会话设置SET ANSI_NULLS相当于数据库选项ANSI NULLS。当这个选项为真是,所有与空值的比较都将得出FALSE,代码必须使用IS NULL条件来判断是否为空,而当这个选项为假时,如果进行比较的两个值都是空值将得出TRUE,SQL Server允许将 =NULL作为IS NULL的同义词,将<> NULL 作为IS NOT NULL的同义词。
    如果忘记这个选项,建议用IS NULL判断空,IS NOT NULL判断非空。
    测试如下:

     在t3表中只有两行数据,如图:
  

    SET ANSI_NULLS OFF 时:

  

    SET ANSI_NULLS ON 时