Tell me more ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I would like to know what are the pros and cons to two apparently valid philosophies regarding the programming of an application which makes extensive use of a database.

The first philosophy is to put as much logic inside the SQL used to query the database which will elaborate the various tables and return an almost ready result to the program.

The second philosophy is to query only the strict necessary data from database and elaborate that data with the programming language used.

The differences I came with so far are these:

I) Querying the database yields better performance and less data has to be copied to memory.

II) Elaborating the data with a programming language may be easier than using complex queries in SQL.

III) Elaborating data in the programming language may be more portable than using a specific SQL dialect, after all iteration and arrays of String, Int and Dates can be easily ported to different languages, a difference in SQL dialect on a very complex SQL query may be much less straight-forward.

Can someone please give some insight on the topic?

Thank you

share|improve this question

closed as not constructive by Jim G., Glenn Nelson, ElYusubov, MichaelT, GlenH7 Feb 4 at 14:49

As it currently stands, this question is not a good fit for our Q&A; format. We expect answers to be supported by facts, references, or specific expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, see the FAQ for guidance.

1 Answer

You've already named the most important aspects. Usually these are the ones you should consider when deciding how to design your system.

An additional point is that anything you do to the data in an external program must be repeated in any other external program that uses the same database (even if there are no other clients at the moment, valuable business data bases have a tendency to acquire other clients, as interested parties from all over the business request "just one little report for our department"). Conversely, if you already have multiple clients and they really do need the data in different formats, then it will be better to deliver raw data and let each client do its own formatting (unless you can define all that's neded via VIEWs).

share|improve this answer
The aspect you pointed out (concurrency I would name it) wouldn't apply if my program were designed as an interface to the database and everyone had to pass through it and eventually extend it if they wanted their purposely formatted data from database. – dendini Feb 4 at 11:55

Not the answer you're looking for? Browse other questions tagged or ask your own question.