V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX  ›  JasonLaw  ›  全部回复第 19 页 / 共 37 页
回复总数  728
1 ... 15  16  17  18  19  20  21  22  23  24 ... 37  
@chengyiqun #111 SQL ? NoSQL ?还是 NewSQL ?
@fkdog #99 “NULL 造成无效索引”?

https://www.v2ex.com/t/694500
@sy20030260 #96 我只是说国外大多数人会选择使用外键。

你应该是从这个 Reddit 找到那个 issue 的。

https://www.reddit.com/r/programming/comments/dtls30/at_github_we_do_not_use_foreign_keys_ever_anywhere/
@fkdog #95 希望大家都就事论事,不要说有的没的。外键最重要的作用是保证 referential integrity 。关于“ 删除一个 user,直接清空了与该 user 有关联的所有表的所有数据”,这个是显式声明了 ON DELETE CASCADE 。
@skiy #84 让我想起了以下这几段话。(来源: https://stackoverflow.com/a/85298/5232255

This is an issue of upbringing. If somewhere in your educational or professional career you spent time feeding and caring for databases (or worked closely with talented folks who did), then the fundamental tenets of entities and relationships are well-ingrained in your thought process. Among those rudiments is how/when/why to specify keys in your database (primary, foreign and perhaps alternate). It's second nature.

If, however, you've not had such a thorough or positive experience in your past with RDBMS-related endeavors, then you've likely not been exposed to such information. Or perhaps your past includes immersion in an environment that was vociferously anti-database (e.g., "those DBAs are idiots - we few, we chosen few java/c# code slingers will save the day"), in which case you might be vehemently opposed to the arcane babblings of some dweeb telling you that FKs (and the constraints they can imply) really are important if you'd just listen.

Most everyone was taught when they were kids that brushing your teeth was important. Can you get by without it? Sure, but somewhere down the line you'll have less teeth available than you could have if you had brushed after every meal. If moms and dads were responsible enough to cover database design as well as oral hygiene, we wouldn't be having this conversation. :-)
@illuz #78 所以我在#67 贴出了 reddit 上的一些讨论
@msg7086 #75 保证 referential integrity
@msg7086 #73 ON DELETE CASCADE 是可选的。
@msg7086 #71

更加准确的说,是数据库的 foreign key constraint 。

“物理外键删数据的时候连 hook 都不会走,天知道会漏跑什么东西”是什么意思?可以具体描述一下吗?
@fengpan567 #68 请问你有使用 primary key, unique 等数据库提供的约束吗?有使用事务吗?
@illuz #66 能够提供一下你所查阅的资料吗?我看到的绝大多数都是倾向使用外键的。

Google 搜索“foreign key database or application reddit”得到的一些结果:

* Are foreign keys really necessary in a database design? : programming - https://www.reddit.com/r/programming/comments/6xidz/are_foreign_keys_really_necessary_in_a_database/
* What Would Happen If Foreign Keys Not Used? : Database - https://www.reddit.com/r/Database/comments/ef38aq/what_would_happen_if_foreign_keys_not_used/
* Don't Most Databases Have Foreign Key Constraints? : SQLServer - https://www.reddit.com/r/SQLServer/comments/6wz2hu/dont_most_databases_have_foreign_key_constraints/dmd7dj1/
* ...
@agagega #55
@JasonLaw #61
@Rocketer #63

这里纠正一下,外键跟一致性( Consistency )没有太大的关系,更正确的说法是:外键能够保证 referential integrity 。Consistency 不是数据库本身的一个特性,它是应用怎么使用数据库的一个特性。
@passerbytiny #57 什么叫数据库编程?什么叫应用编程?
@agagega #55 同意你所说的“ 互联网公司的业务不太追求完整的数据一致性”
@Rocketer #54

我还是不明白,为什么“需求不明确”就开始开工了?就不建议使用外键了?

你说的分布式数据库指的是 NoSQL 数据库吗?
@zjsxwc #40 是有一点道理,不过要保证 referential integrity,也只有数据库外键才能做到。
@gBurnX #37 同意
@zjsxwc #24 个人感觉,这个是设计的问题,不是外键的问题,不在部门表存储负责人就行了,使用关系表解决。想象一下,把三个实体当作 Spring 中的 service 的话,它们也会造成循环依赖。
@alamaya #29 这样子的话,你也无法达到数据库外键所能实现的效果,应用代码还复杂多了。
@wqtacc #27 那怎么解决#15 所描述的问题?再激进一点的话,那还要事务干嘛,直接应用层解决不行吗?干嘛让数据库做这么多事情来保证 AID ?
1 ... 15  16  17  18  19  20  21  22  23  24 ... 37  
关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   2095 人在线   最高记录 6679   ·     Select Language
创意工作者们的社区
World is powered by solitude
VERSION: 3.9.8.5 · 14ms · UTC 01:15 · PVG 09:15 · LAX 17:15 · JFK 20:15
Developed with CodeLauncher
♥ Do have faith in what you're doing.