put your logo here

Eduardo's blog

数据库设计原则:真相就在那里 (The principles of database design, or, the Truth is out there) May 17, 2025 by Eduardo Bellani

每个软件项目都需要呈现其所嵌入业务的真实情况。我们这些理性的、有限的存在,表示现实的方式是通过命题,即声明现实的肯定或否定陈述。当这些命题的集合存储在计算机系统中时,我们称之为数据库。

这样的数据库需要被设计成能够正确地反映现实。这不能自动化,因为情况的语义需要以一种可以被计算机处理的方式编码。因此,数据库设计的目的是:以一种可以被数据库管理系统 (DBMS) 正确处理的方式编码命题。

在这一点上,一个普通的软件开发人员会陷入停滞。由于他的教育中几乎没有任何关于数据库设计(或形式逻辑)的正式培训,他倾向于随意地求助于临时方法,这会产生严重的后果(更新异常和数据不一致,具有巨大的潜在负面影响)。

如果你是这样的开发者,你需要理解数据库设计的底层原则。想想看,如果你没有设计原则,那你不是在做工程,对吗?

以下是进行正式数据库设计时要遵循的设计原则列表 (McGoveran 2012, 2015) (Pascal 2016):

我想在此基础上介绍一个新原则,我希望在未来的工作中进一步发展:

以下伪 SQL 代码显示了不正确的指称和正确的指称之间的对比:

-- usage of surrogate keys
createtablecitizen(iduuidprimarykey,national_idtext,full_nametext);

代码片段 1:使用 SQL 说明不使用 PED

这种用法存在一些问题,其中最糟糕的是数据库结构和域语义之间的脱节。以下是一个保留这种连接的修改:

createdomainnational_idastextcheck(...);createtablecitizen(national_idnational_idprimarykey,full_nametext);

代码片段 2:使用 SQL 说明使用 PED

结论

数据库是现实的表示,因此,它们是任何严肃的信息系统的基础。糟糕的设计会导致语义混乱和技术不稳定 - 其后果可能是代价高昂且影响深远的。好的设计需要严谨、自律和对基本原则的牢固掌握。

简单来说:如果你从事信息业务,你需要知道如何构建讲述真相的结构。

参考文献

Blakemore, Erin. 2019. “The Notre-Dame Cathedral Was Nearly Destroyed by French Revolutionary Mobs (Accessed on 2025-05-18).” https://web.archive.org/web/20190607211856/https://www.history.com/news/notre-dame-fire-french-revolution. McGoveran, David. 2012. “Updating a Database.” Alternative Technologies Blog. http://w.alternativetech.com/publications/View%20Updating%206-12-12.pdf. ———. 2015. “Can All Relations Be Updated? (or Can Any Relation Be Updated?) Logic for Serious Database Folks Series.” Alternative Technologies Blog. https://www.alternativetech.com/publications/Logic%20for%20DB%20Folks%20Series%20XX%20-%20Updating%20Relations.pdf. Pascal, Fabian. 2016. “The Principle of Orthogonal Database Design Part I.” https://www.dbdebunk.com/2016/09/the-principle-of-orthogonal-database.html. Figure 1: But revolutionary Parisians had had enough of its royal resonance. The cathedral’s west facade featured 28 statues that portrayed the biblical Kings of Judah. In fall 1793, the new government ordered workers to remove them. They didn’t portray French kings, but no matter: The 500-year-old statues combined monarchy and religion, and they were brought to the cathedral’s square and decapitated. Twenty-one of the heads were only recovered in 1977, when workers found them behind a wall in an old Parisian mansion.(Blakemore 2019) 图 1:但是,革命的巴黎人已经受够了它的皇家共鸣。大教堂的西面外墙有 28 座描绘圣经犹大国王的雕像。1793 年秋天,新政府下令工人将其拆除。他们没有描绘法国国王,但这没关系:500 年历史的雕像结合了君主制和宗教,它们被带到大教堂广场并被斩首。直到 1977 年,工人们在巴黎一座老豪宅的墙后发现了它们,才找回了其中的 21 个头像。 (Blakemore 2019) Feel free to send me an email: ebellani -at- gmail -dot- com Fingerprint: 48C50C6F1139C5160AA0DC2BC54D00BC4DF7CA7C