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

推荐订阅源

酷 壳 – CoolShell
酷 壳 – CoolShell
H
Hacker News: Front Page
P
Palo Alto Networks Blog
T
ThreatConnect
Apple Machine Learning Research
Apple Machine Learning Research
博客园_首页
T
True Tiger Recordings
P
Privacy & Cybersecurity Law Blog
B
Blog
IT之家
IT之家
Last Week in AI
Last Week in AI
F
Full Disclosure
Hacker News: Ask HN
Hacker News: Ask HN
C
Comments on: Blog
Microsoft Azure Blog
Microsoft Azure Blog
C
Cybersecurity and Infrastructure Security Agency CISA
Microsoft Security Blog
Microsoft Security Blog
博客园 - 【当耐特】
N
News and Events Feed by Topic
NISL@THU
NISL@THU
腾讯CDC
雷峰网
雷峰网
Security Latest
Security Latest
李成银的技术随笔
M
Microsoft Research Blog - Microsoft Research
L
LangChain Blog
L
Lohrmann on Cybersecurity
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Check Point Blog
Y
Y Combinator Blog
Recent Announcements
Recent Announcements
博客园 - Franky
N
News | PayPal Newsroom
V
V2EX
A
About on SuperTechFans
The Register - Security
The Register - Security
月光博客
月光博客
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Google Online Security Blog
Google Online Security Blog
MyScale Blog
MyScale Blog
Cisco Talos Blog
Cisco Talos Blog
Vercel News
Vercel News
WordPress大学
WordPress大学
C
Cyber Attacks, Cyber Crime and Cyber Security
The Hacker News
The Hacker News
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
IntelliJ IDEA : IntelliJ IDEA – the Leading IDE for Professional Development in Java and Kotlin | The JetBrains Blog
爱范儿
爱范儿
A
Arctic Wolf
L
LINUX DO - 最新话题
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

博客园 - Jiger

TypeScript 编译目标(target)设置 微软下一代Web前端技术Blazor(C#编译为WebAssembly) LinqPad的变量比较功能 Web后台技术趋势 - Jiger MSBI - KPI 所有的列表都应该考虑排序 - Jiger 产品应该努力提高用户使用的方便性 上传和下载控制协议 - Jiger CSV文件的规范 Silverlight商业应用实例-新浪财经银光版 前台线程和后台线程的区别 笔记:如何让wpf中disabled的控件弹出右键菜单 - Jiger xaml数据绑定时字段不存在的错误处理方法 - Jiger jQuery中bind函数绑定多个事件 StringFormat绑定语法中的问题 - Jiger wpf/silverlight指定空值特殊显示的语法 jQuery的ajax函数中timeout参数的默认值 Visual Studio中Website和Web Application Project的区别 Silverlight 2.0 学习笔记王计平版-01-开始学习XAML
数据库的NULL值讨论
Jiger · 2016-01-28 · via 博客园 - Jiger

有许多关于数据库设计中NULL的讨论,我个人的设计习惯是,不使用NULL值。

我所设计所有表都是Not Null的字段的,尤其是我主要做数据仓库的表设计。刚开始使用数据库时,就栽了一次。一个Group里面,我要显示成年人有多少个,另外一个地方要显示未成年人有多少个,第三个地方要显示总人数。

N1(成年人数) = select count(*) from mygroup where age>=18; 结果是10

N2(未成年人) = select count(*) from mygorup where age< 18; 结果是12

到第三个地方,为了减少查询,我直接显示了 10+12 = 22 人。后来客户说不对呀,我们有23个人,想了半天才明白怎么回事,后来我经常拿这个考别人。

NULL使用起来很不方便。在各种编程语言中都支持这样的表达式 if(x==null) {...}. 但是在数据库理论中,null比较"奇怪"逻辑.

3 > null, 返回false;
3 < null, 返回false;
3 = null, 返回false.

为了配合数据库的NULL值机制,C#引入了nullable机制,比如:int? v1 = field("age").value; 否则如果age的值是null,无法赋值给v1.