Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dynamic sql vs stored procedures - pros and cons?

I have read many strong views (both for and against) SPs or DS.

I am writing a query engine in C++ (mySQL backend for now, though I may decide to go with a C++ ORM). I cant decide whether to write a SP, or to dynamically creat the SQL and send the query to the db engine.#

Any tips on how to decide?

like image 842
skyeagle Avatar asked May 04 '10 23:05

skyeagle


2 Answers

Here's the simple answer:

If your programmers do both database and coding work, keep the SQL with the app. It's easier to maintain that way. Otherwise, let the DB guys handle it in SPs.

like image 87
Sophtware Avatar answered Sep 30 '22 19:09

Sophtware


You have more control over the mechanisms outside the database. The biggest win for taking care of this outside the database is simply maintenance (in my mind). It'd be slightly hard to version control the SP vs the code you generate outside the database. One more thing to keep track of.

While we're on the topic, it's similar to handling data/schema migrations. It's annoyingly complex to version/handle schema migrations, if you don't already have a mechanism for this, you will have yet another thing you'll need to manage. It comes down to simply being easier to manage/version these things outside the database.

Consider the scenario where you have a bug in your SP. Now it needs to be changed, but then you hop over to another developers database/sandbox. What version is the sandbox and the SP? Now you have to track multiple versions.

like image 44
dlamotte Avatar answered Sep 30 '22 19:09

dlamotte