数据库层中的业务逻辑 [英] business logic in database layer

查看:229
本文介绍了数据库层中的业务逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不想再次提出数据库与代码中的业务逻辑"这一经典问题,但是我需要一些具体的理由来说服一个较老的开发人员团队,认为代码中的业务逻辑更好,因为它更易于维护,尤其是在其他方面.我曾经在数据库中有很多业务逻辑,因为我相信这是单点访问.如果我是唯一进行更改的人,那么维护很容易.以我的经验,当项目变得更大和复杂时,问题就来了.数据库存储过程的源代码管理没有更新的IDE的高级,编辑器也没有.我最近的经验发现,代码中的业务逻辑可以比数据库中的业务逻辑更好地扩展.

I hate to ask the classic question of "business logic in database vs code" again, but I need some concrete reasons to convince an older team of developers that business logic in code is better, because it's more maintainable, above all else. I used to have a lot of business logic in the DB, because I believed it was the single point of access. Maintenance is easy, if I was the only one doing the changing it. In my experience, the problems came when the projects got larger and complicated. Source Control for DB Stored Procs are not so advanced as the ones for newer IDEs, nor are the editors. Business logic in code can scale much better than in the DB, is what I've found in my recent experience.

因此,我只是在研究stackoverflow时,发现了与其尊敬的成员截然相反的理念:

So, just searching around stackoverflow, I found quite the opposite philosophy from its esteemed members:

https://stackoverflow.com/search?q=business+logic+in+database

我知道在任何情况下都不是绝对的,但是对于给定的asp.net解决方案(对于流量不是特别高的站点),该解决方案将使用sql server或oracle,为什么要将逻辑放在DB中?

I know there is no absolute for any situation, but for a given asp.net solution, which will use either sql server or oracle, for a not a particularly high traffic site, why would I put the logic in the DB?

推荐答案

取决于您所说的业务.

数据库应该完成预期的工作.

The database should do what is expected.

如果数据的使用者和提供者希望数据库做出某些保证,则需要在数据库中完成.

If the consumers and providers of data expect the database to make certain guarantees, then it needs to be done in the database.

有些人不在他们的数据库中使用引用完整性,而是希望系统的其他部分来管理引用完整性.有些人直接访问数据库中的表.

Some people don't use referential integrity in their databases and expect the other parts of the system to manage that. Some people access tables in the database directly.

我觉得从系统和组件的角度来看,数据库就像其他任何服务或类/对象一样.它需要保护其外围,隐藏其实现细节并提供从低级完整性到特定级别(可以被视为业务")的完整性保证.

I feel that from a systems and component perspective, the database is like any other service or class/object. It needs to protect its perimeter, hide its implementation details and provide guarantees of integrity, from low-level integrity up to a certain level, which may be considered "business".

做到这一点的好方法是引用完整性,存储过程,触发器(必要时),视图,隐藏基表等,等等.

Good ways to do this are referential integrity, stored procedures, triggers (where necessary), views, hiding base tables, etc., etc.

这篇关于数据库层中的业务逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆