Business logic in a database layer

I no longer like the classic question “business logic in the database versus code”, but I need some specific reasons to convince the senior development team that business logic in the code is better because it is more convenient to maintain, first of all , I used to have a lot of business logic in the database, because I thought it was the only access point. Maintenance is easy if I was the only one who changed it. In my experience, problems arose when projects became larger and more complex. The initial controls for stored in DB Procs are not as advanced as those for the new IDEs and are not editors. The business logic in the code can scale much better than in the database, this is what I found in my recent experience.

So, just looking through stackoverflow, I found the exact opposite philosophy from my esteemed members:

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

I know that for any situation there is no absolute, but for this solution asp.net, which will use either a sql server or oracle, for not very high traffic, why should I put the logic in the database?

+1
database oracle sql-server business-logic
Aug 10 '11 at 3:00 a.m.
source share
2 answers

Depends on what you call a business.

The database should do what is expected.

If consumers and data providers expect the database to provide certain guarantees, this must be done in the database.

Some people do not use referential integrity in their databases and expect other parts of the system to handle this. Some people access tables in the database directly.

I feel that from the point of view of systems and components, a database is like any other service or class / object. It must protect its perimeter, hide its implementation details and provide integrity guarantees, from low-level integrity to a certain level that can be considered a "business".

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

+6
Aug 10 '11 at 3:12
source share

The database runs the data, so weigh what has already hit hard to give you the data. This is a thing of execution and a thing of code. Maintaining business logic code is much easier than storing it all in a database. Sprocs, Views, and Functions can only work until you have Views Views of Views with sprocs to fill this clutter. In business logic, you share your concerns. If you have an error due to which something is being calculated incorrectly, it is easier to check the business logic code than go into the database and see that someone has mixed up something in the stored procedure. This is very stubborn, and in some cases it’s normal to put some logic in the database, but my thoughts on this is the database, not the logical database, put things where they belong.

PS: Maybe there is a little warmth for this post, it is very stubborn and different from the performance numbers, there is no real evidence there, and this becomes the case of what you are working with.

EDIT: Something that Cade mentioned that I forgot. Illegal integrity. By all means, you have the correct data integrity in your database, there are no lost records ON DELETE CASCADE, checks and much more.

+1
Aug 10 2018-11-11T00:
source share



All Articles