应用程序开发人员常见的数据库开发错误有哪些?
当前回答
1)不了解如何正确地在Java和数据库之间进行交互。
2)过度解析,不恰当或没有重用SQL
3)没有使用BIND变量
4)在数据库中使用SQL集逻辑时,用Java实现过程逻辑(更好)。
5)在投入生产前没有进行任何合理的性能或可伸缩性测试
6)使用水晶报表,在报表中没有正确设置模式名
7)由于不了解执行计划,使用笛卡尔式产品实现SQL(你甚至看了EXPLAIN计划吗?)
其他回答
开发人员所犯的关键数据库设计和编程错误
Selfish database design and usage. Developers often treat the database as their personal persistent object store without considering the needs of other stakeholders in the data. This also applies to application architects. Poor database design and data integrity makes it hard for third parties working with the data and can substantially increase the system's life cycle costs. Reporting and MIS tends to be a poor cousin in application design and only done as an afterthought. Abusing denormalised data. Overdoing denormalised data and trying to maintain it within the application is a recipe for data integrity issues. Use denormalisation sparingly. Not wanting to add a join to a query is not an excuse for denormalising. Scared of writing SQL. SQL isn't rocket science and is actually quite good at doing its job. O/R mapping layers are quite good at doing the 95% of queries that are simple and fit well into that model. Sometimes SQL is the best way to do the job. Dogmatic 'No Stored Procedures' policies. Regardless of whether you believe stored procedures are evil, this sort of dogmatic attitude has no place on a software project. Not understanding database design. Normalisation is your friend and it's not rocket science. Joining and cardinality are fairly simple concepts - if you're involved in database application development there's really no excuse for not understanding them.
有一件事我想补充,学习使用分析函数,如分区BY, RANK, DENSE_RANK (Oracle)。它们对于复杂的查询是绝对必要的。
其他建议是,如果可能的话,在您的开发团队中有一个专门的数据库开发人员,他应该是SQL、数据库建模、调优等方面的专家(但不是DBA)。这种技能是一笔巨大的财富。
使用Excel存储(大量)数据。
我曾见过一些公司拥有数千行并使用多个工作表(由于以前版本的Excel的行数限制为65535)。
Excel非常适合用于报告、数据演示和其他任务,但不应被视为数据库。
我讨厌开发人员使用嵌套的选择语句,甚至在查询的“select”部分中返回选择语句的结果的函数。
我很惊讶我在其他地方没有看到这个,也许我忽略了它,尽管@adam也有类似的问题。
例子:
SELECT
(SELECT TOP 1 SomeValue FROM SomeTable WHERE SomeDate = c.Date ORDER BY SomeValue desc) As FirstVal
,(SELECT OtherValue FROM SomeOtherTable WHERE SomeOtherCriteria = c.Criteria) As SecondVal
FROM
MyTable c
在这个场景中,如果MyTable返回10000行,结果就好像查询只运行了20001个查询,因为它必须运行初始查询,并对每一行结果查询一次其他表。
开发人员可以在只返回几行数据且子表通常只有少量数据的开发环境中使用这种查询,但在生产环境中,随着向表中添加更多数据,这种查询的成本可能会呈指数级增长。
一个更好的(不一定完美的)例子是这样的:
SELECT
s.SomeValue As FirstVal
,o.OtherValue As SecondVal
FROM
MyTable c
LEFT JOIN (
SELECT SomeDate, MAX(SomeValue) as SomeValue
FROM SomeTable
GROUP BY SomeDate
) s ON c.Date = s.SomeDate
LEFT JOIN SomeOtherTable o ON c.Criteria = o.SomeOtherCriteria
这允许数据库优化器将数据混合在一起,而不是从主表中重新查询每条记录,我通常发现,当我必须修复产生这个问题的代码时,我通常会将查询速度提高100%或更多,同时减少CPU和内存使用。
a)在字符串中硬编码查询值 b)将数据库查询代码放在Windows窗体应用程序的“OnButtonPress”操作中
两者我都见过。
推荐文章
- 获得PostgreSQL数据库中当前连接数的正确查询
- MySQL数据库表中的最大记录数
- 从现有模式生成表关系图(SQL Server)
- HyperLogLog算法是如何工作的?
- 数据库和模式的区别
- 如何从命令行在windows中找到mysql数据目录
- 货币应该使用哪种数据类型?
- 如何找到MySQL的根密码
- 将表从一个数据库复制到另一个数据库的最简单方法?
- 什么是分片,为什么它很重要?
- 数据库触发器是必要的吗?
- 为什么我应该使用基于文档的数据库而不是关系数据库?
- 哪个更快/最好?SELECT *或SELECT columnn1, colum2, column3等
- 将值从同一表中的一列复制到另一列
- 什么是数据库池?