Anonym
Anonym

Reputation: 7725

Is storing SQL queries in a database a bad thing?

We're thinking of storing SQL queries in a separate table. These queries are solely for reporting purposes. Different queries for different reports - moreover the queries would contain placeholders so we can either format or use prepared statements from the Winforms front end (it's a simple 2-tier reporting app) to e.g. format the date range to report on.

I'm having some mixed feelings about that - is it ok to store SQL in a table, that clients will fetch and run?

Upvotes: 6

Views: 3490

Answers (2)

Aiden Bell
Aiden Bell

Reputation: 28384

I agree with Gregoire -- stored procedures are a good way forward, if your language works well with them.

Otherwise, ask:

What's the difference between storing them in source, XML files, SQL etc.? Storage is storage is storage... The potential damage of misuse and implementing without considering the constraints in relation to your app is what counts.

Upvotes: 12

Behrang Saeedzadeh
Behrang Saeedzadeh

Reputation: 47933

In my opinion that looks like a quick and dirty solution. What if in the future you wanted to migrate to another DB engine with a different SQL dialect? A better solution is to create a report object model (or xml model) and map it to a corresponding DB schema. This requires more time and effort though.

Upvotes: 0

Related Questions