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

推荐订阅源

Hacker News: Ask HN
Hacker News: Ask HN
C
Cisco Blogs
The Hacker News
The Hacker News
T
Tor Project blog
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
The GitHub Blog
The GitHub Blog
A
Arctic Wolf
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
The Register - Security
The Register - Security
云风的 BLOG
云风的 BLOG
Simon Willison's Weblog
Simon Willison's Weblog
P
Palo Alto Networks Blog
Vercel News
Vercel News
C
CERT Recently Published Vulnerability Notes
I
InfoQ
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
M
MIT News - Artificial intelligence
I
Intezer
aimingoo的专栏
aimingoo的专栏
U
Unit 42
C
Cyber Attacks, Cyber Crime and Cyber Security
L
LINUX DO - 热门话题
Microsoft Security Blog
Microsoft Security Blog
酷 壳 – CoolShell
酷 壳 – CoolShell
Cyberwarzone
Cyberwarzone
P
Proofpoint News Feed
P
Proofpoint News Feed
B
Blog
T
Threat Research - Cisco Blogs
博客园 - 叶小钗
Recorded Future
Recorded Future
Last Week in AI
Last Week in AI
N
News and Events Feed by Topic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Know Your Adversary
Know Your Adversary
Engineering at Meta
Engineering at Meta
G
Google Developers Blog
PCI Perspectives
PCI Perspectives
Google DeepMind News
Google DeepMind News
WordPress大学
WordPress大学
Application and Cybersecurity Blog
Application and Cybersecurity Blog
MyScale Blog
MyScale Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Schneier on Security
Schneier on Security
N
News | PayPal Newsroom
C
Cybersecurity and Infrastructure Security Agency CISA
H
Help Net Security
博客园 - 聂微东
H
Hackread – Cybersecurity News, Data Breaches, AI and More
G
GRAHAM CLULEY

博客园 - Jiger

TypeScript 编译目标(target)设置 微软下一代Web前端技术Blazor(C#编译为WebAssembly) LinqPad的变量比较功能 Web后台技术趋势 MSBI - KPI 所有的列表都应该考虑排序 产品应该努力提高用户使用的方便性 上传和下载控制协议 CSV文件的规范 Silverlight商业应用实例-新浪财经银光版 前台线程和后台线程的区别 笔记:如何让wpf中disabled的控件弹出右键菜单 - Jiger - 博客园 xaml数据绑定时字段不存在的错误处理方法 jQuery中bind函数绑定多个事件 StringFormat绑定语法中的问题 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.