Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Where to put your code - Database vs. Application? [closed]

Tags:

database

I have been developing web/desktop applications for about 6 years now. During the course of my career, I have come across application that were heavily written in the database using stored procedures whereas a lot of application just had only a few basic stored procedures (to read, insert, edit and delete entity records) for each entity.

I have seen people argue saying that if you have paid for an enterprise database use its features extensively. Whereas a lot of "object oriented architects" told me its absolute crime to put anything more than necessary in the database and you should be able to drive the application using the methods on those classes?

Where do you think is the balance?

Thanks, Krunal

like image 474
Krantz Avatar asked Aug 22 '08 16:08

Krantz


People also ask

Should I put business logic in the database?

DATA logic should be in the database. The way you manipulate the database structures to perform the activities required by the functionality SHOULD BE held in the database. When you join up these activities into a larger series of processes (business logic) then THIS can be consolidated in the application.

How does a database connect to an application?

'connS' contains the connection string. This is what allows an application to open a connection and execute a SQL query with a database. Within it, you can see that the server and database names are provided, as well as what credentials are needed (same ones used to access the database via SSMS).

Does every application need a database?

Do you always need a database for your app? Of course not. As with everything in technology, nothing is ideal in every situation. Computers offer many various ways to store data.

Can you store code in a database?

Oracle Database offers the ability to store program code in the database. Developers write program code in PL/SQL or Java, and store the code in schema objects. You, as the DBA, can use SQL Developer to manage program code objects such as: PL/SQL packages, procedures, functions, and triggers.


2 Answers

I think it's a business logic vs. data logic thing. If there is logic that ensures the consistency of your data, put it in a stored procedure. Same for convenience functions for data retrieval/update.

Everything else should go into the code.

A friend of mine is developing a host of stored procedures for data analysis algorithms in bioinformatics. I think his approach is quite interesting, but not the right way in the long run. My main objections are maintainability and lacking adaptability.

like image 105
Konrad Rudolph Avatar answered Nov 16 '22 02:11

Konrad Rudolph


I'm in the object oriented architects camp. It's not necessarily a crime to put code in the database, as long as you understand the caveats that go along with that. Here are some:

  1. It's not debuggable
  2. It's not subject to source control
  3. Permissions on your two sets of code will be different
  4. It will make it more difficult to track where an error in the data came from if you're accessing info in the database from both places
like image 24
TheSmurf Avatar answered Nov 16 '22 01:11

TheSmurf