不管我们喜欢与否,我们开发人员中的许多人(如果不是大多数的话)都经常使用数据库,或者有一天可能不得不使用数据库。考虑到大量的误用和滥用,以及每天出现的大量与数据库相关的问题,公平地说,有一些概念是开发人员应该知道的——即使他们今天不设计或使用数据库。

关于数据库,开发人员和其他软件专业人员应该知道的一个重要概念是什么?


当前回答

我希望每个人,包括dba和开发人员/设计人员/架构师,都能更好地理解如何正确地对业务领域建模,以及如何将业务领域模型映射/转换为规范化的数据库逻辑模型、优化的物理模型和适当的面向对象类模型(每种模型由于各种原因(可能)不同),并理解何时、为什么以及它们(或应该)如何彼此不同。

其他回答

根据我使用关系数据库的经验,每个开发人员都应该知道:

—不同的数据类型:

为正确的工作使用正确的类型将使您的DB设计更健壮,查询更快,生活更轻松。

—了解1xM和MxM:

这是关系数据库的基本功能。您需要理解一对多和多对多关系,并在适当的时候应用它们。

“K.I.S.S.”原则也适用于DB

简单总是最好的。如果你已经学习了数据库是如何工作的,你将避免不必要的复杂性,这将导致维护和速度问题。

——指数:

光知道它们是什么是不够的。你需要知道什么时候使用,什么时候不使用。


另外:

布尔代数是你的朋友 图像:不要将它们存储在DB上。不要问为什么。 用SELECT测试DELETE

基本的SQL技能。 索引。 处理DATE/ TIME/ TIMESTAMP的不同形式。 用于您正在使用的平台的JDBC驱动程序文档。 处理二进制数据类型(CLOB、BLOB等)

除了他们使用的语法和概念选项(例如连接、触发器和存储过程)之外,对于每个使用数据库的开发人员来说,有一件事是至关重要的:

了解您的引擎将如何执行您正在编写的查询。

我认为这很重要的原因仅仅是生产的稳定性。您应该知道您的代码是如何执行的,这样您就不会在等待一个长函数完成时停止线程中的所有执行,那么为什么您不想知道您的查询将如何影响数据库、程序甚至服务器呢?

This is actually something that has hit my R&D team more times than missing semicolons or the like. The presumtion is the query will execute quickly because it does on their development system with only a few thousand rows in the tables. Even if the production database is the same size, it is more than likely going to be used a lot more, and thus suffer from other constraints like multiple users accessing it at the same time, or something going wrong with another query elsewhere, thus delaying the result of this query.

即使是像连接如何影响查询性能这样简单的事情,在生产中也是非常宝贵的。许多数据库引擎的许多特性在概念上让事情变得更简单,但如果没有考虑清楚,可能会在性能上带来问题。

了解数据库引擎的执行过程,并为之制定计划。

好问题。以下是一些想法,排名不分先后:

Normalization, to at least the second normal form, is essential. Referential integrity is also essential, with proper cascading delete and update considerations. Good and proper use of check constraints. Let the database do as much work as possible. Don't scatter business logic in both the database and middle tier code. Pick one or the other, preferably in middle tier code. Decide on a consistent approach for primary keys and clustered keys. Don't over index. Choose your indexes wisely. Consistent table and column naming. Pick a standard and stick to it. Limit the number of columns in the database that will accept null values. Don't get carried away with triggers. They have their use but can complicate things in a hurry. Be careful with UDFs. They are great but can cause performance problems when you're not aware how often they might get called in a query. Get Celko's book on database design. The man is arrogant but knows his stuff.

阻抗失配问题,并了解常见缺陷或orm。