Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Howto test SQL statements and ensure their quality?

Tags:

sql

testing

I am working on some business intelligence reports these days. The data is fetched by ordinary SQL SELECT statements. The statements are getting more and more complex.

The data I want to report is partially business critical. So I would feel better, if I could do something to proof the correctness and quality of the SQL statements.

I know there are some ways to do this for application-code. But what can I do to reach these goals at SQL level?

Thanks in advance.

like image 335
c0d3x Avatar asked Oct 27 '25 00:10

c0d3x


1 Answers

I'm not aware of any SQL-level proof of QA you could do since you are looking for the intent (semantics) of the query rather than syntactical correctness.

I would write a small test harness that takes the SQL statement and runs it on a known test database, then compare the result with an expecetd set of reference data (spreadsheet, simple CSV file etc).

For bonus points wrap this in a unit test and make it part of your continuous build process.

If you use a spreadsheet or CSV for the reference data it may be possible to walk through it with the business users to capture their requirements ahead of writing the SQL (i.e test-driven development).

like image 59
Paolo Avatar answered Oct 29 '25 17:10

Paolo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!