...

/

Business Logic in the Database

Business Logic in the Database

Learn how to embed business logic in a database and where business logic is applied.

Business logic and the databases

Maintaining business logic can be a hard task. Each application might be different, and every development team might have a different viewpoint here, from one extreme—maintaining all of it in the application—to the other extreme—maintaining it all in the database server with the help of stored procedures.

Our view is that every SQL query embeds some parts of the business logic we’re implementing. Therefore, the question changes from should we have business logic in the database to how much of our business logic should be maintained in the database.

The main aspects to consider in terms of where to maintain the business logic are correctness and the efficiency of our code architecture and organization.

Business logic in SQL statements

Before we dive into more specifics, we need to realize that as soon as we send a SQL query to our RDBMS, we’re already sending business logic to the database. All SQL queries contain some level of business logic. Let’s consider a few examples.

Approach one

In the ...