Tune the ‘Peak Years’ Procedure – SQLChallenge (52 minutes)

Ready to tune some TSQL? In this challenge, you’re given a database to restore. You’ll create two indexes and a constraint in the database– and you aren’t allowed to change those.

Your mission, if you choose to accept it, is to tune the TSQL in a stored procedure so it can make the best use of the given indexes — and still returns the same results. You’re given two sample calls to the procedure, and your goal is to make it as fast as possible.

Note on the database

This SQLChallenge uses the same sample database as the Query Tuning Jam Session recorded seminar. It’s a fresh new challenge that isn’t duplicated from that course – I simply used the same database for convenience. If you’ve already downloaded and restored the backup from that course, go ahead and use it for this! And if you haven’t done that session yet, it’s a great one to tackle after this course: it’s full of different queries to tune.