不管我们喜欢与否,我们开发人员中的许多人(如果不是大多数的话)都经常使用数据库,或者有一天可能不得不使用数据库。考虑到大量的误用和滥用,以及每天出现的大量与数据库相关的问题,公平地说,有一些概念是开发人员应该知道的——即使他们今天不设计或使用数据库。
关于数据库,开发人员和其他软件专业人员应该知道的一个重要概念是什么?
不管我们喜欢与否,我们开发人员中的许多人(如果不是大多数的话)都经常使用数据库,或者有一天可能不得不使用数据库。考虑到大量的误用和滥用,以及每天出现的大量与数据库相关的问题,公平地说,有一些概念是开发人员应该知道的——即使他们今天不设计或使用数据库。
关于数据库,开发人员和其他软件专业人员应该知道的一个重要概念是什么?
当前回答
归一化
我总是很沮丧地看到有人努力编写一个过度复杂的查询,而这个查询用标准化的设计可以完全简单明了(“显示每个地区的总销售额。”)。
如果您在一开始就理解了这一点,并相应地进行设计,您将在以后为自己省去许多痛苦。在规范化之后,很容易对性能进行反规范化;要规范化一个从一开始就不是这样设计的数据库并不容易。
至少,您应该知道3NF是什么以及如何实现它。对于大多数事务性数据库,这是使查询易于编写和保持良好性能之间的一个很好的平衡。
其他回答
避免SQL注入以及如何保护您的数据库
将非正规化视为一个可能的天使,而不是魔鬼,并将NoSQL数据库视为关系数据库的替代方案。
此外,我认为实体-关系模型是每个开发人员必须知道的,即使你不设计数据库。它将让您彻底理解数据库的所有内容。
好问题。以下是一些想法,排名不分先后:
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.
简单的尊重。
它不仅仅是一个存储库 您可能并不比供应商或dba更了解情况 你不会在凌晨3点的时候,在高级经理对你大喊大叫的情况下支持它
除了他们使用的语法和概念选项(例如连接、触发器和存储过程)之外,对于每个使用数据库的开发人员来说,有一件事是至关重要的:
了解您的引擎将如何执行您正在编写的查询。
我认为这很重要的原因仅仅是生产的稳定性。您应该知道您的代码是如何执行的,这样您就不会在等待一个长函数完成时停止线程中的所有执行,那么为什么您不想知道您的查询将如何影响数据库、程序甚至服务器呢?
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.
即使是像连接如何影响查询性能这样简单的事情,在生产中也是非常宝贵的。许多数据库引擎的许多特性在概念上让事情变得更简单,但如果没有考虑清楚,可能会在性能上带来问题。
了解数据库引擎的执行过程,并为之制定计划。