不管我们喜欢与否,我们开发人员中的许多人(如果不是大多数的话)都经常使用数据库,或者有一天可能不得不使用数据库。考虑到大量的误用和滥用,以及每天出现的大量与数据库相关的问题,公平地说,有一些概念是开发人员应该知道的——即使他们今天不设计或使用数据库。
关于数据库,开发人员和其他软件专业人员应该知道的一个重要概念是什么?
不管我们喜欢与否,我们开发人员中的许多人(如果不是大多数的话)都经常使用数据库,或者有一天可能不得不使用数据库。考虑到大量的误用和滥用,以及每天出现的大量与数据库相关的问题,公平地说,有一些概念是开发人员应该知道的——即使他们今天不设计或使用数据库。
关于数据库,开发人员和其他软件专业人员应该知道的一个重要概念是什么?
当前回答
阻抗失配问题,并了解常见缺陷或orm。
其他回答
不要依赖于SQL查询返回的行顺序。
对于一些项目,面向对象模型更好。
对于其他项目,关系模型更好。
根据我使用关系数据库的经验,每个开发人员都应该知道:
—不同的数据类型:
为正确的工作使用正确的类型将使您的DB设计更健壮,查询更快,生活更轻松。
—了解1xM和MxM:
这是关系数据库的基本功能。您需要理解一对多和多对多关系,并在适当的时候应用它们。
“K.I.S.S.”原则也适用于DB
简单总是最好的。如果你已经学习了数据库是如何工作的,你将避免不必要的复杂性,这将导致维护和速度问题。
——指数:
光知道它们是什么是不够的。你需要知道什么时候使用,什么时候不使用。
另外:
布尔代数是你的朋友 图像:不要将它们存储在DB上。不要问为什么。 用SELECT测试DELETE
除了他们使用的语法和概念选项(例如连接、触发器和存储过程)之外,对于每个使用数据库的开发人员来说,有一件事是至关重要的:
了解您的引擎将如何执行您正在编写的查询。
我认为这很重要的原因仅仅是生产的稳定性。您应该知道您的代码是如何执行的,这样您就不会在等待一个长函数完成时停止线程中的所有执行,那么为什么您不想知道您的查询将如何影响数据库、程序甚至服务器呢?
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.