views:

1973

answers:

7

I am trying to become more familiar with SQL by writing queries against the Northwind database.

I am looking for some exercises that would help me to learn SQL and features of SQL Server. It is important that the exercises have solutions, and in complicated cases, it would be great if there was an explanation for the query.

Thanks for the answers so far but I still have not found what I am looking for: Is there any free resource, available online, without registration, that I can find a list of these exercises?

+2  A: 

I would pick up Inside Microsoft SQL Server 2005: T-SQL Querying. This book is great and has exercises + answers

I did an interview with the author a while back about this book, you can find that here: Interview With Itzik Ben-Gan Author Of Inside Microsoft SQL Server 2005: T-SQL Querying

SQLMenace
a good suggestion, unfortunately I was looking for a free resource that is accessible online.
MedicineMan
+1  A: 

there are a series of "try its" I noticed over at w3cschool recently, these may help out

curtisk
helpful, but I need a lot more exercises. Like for the employees table, a nice exercise would have been to list an employee with his manager ("reports to")
MedicineMan
+1  A: 

The best way to learn in my opinion would be to work on a small hobby project.

For instance, lets say you are interested in sports, pick up your favorite sport and envision how you would model the sport statistics in the most elegant way in the form of a SQL database. You would start thinking on the lines of how to pull data out of the db, update the data , so on and so forth.

Whenever you encounter an issue, you can go look at the reference books (The T-SQL querying book mentioned above is a very good one) and figure out the best way of doing it.

Toy examples,exercises are good. But in my opinion, unless you really face a problem and solve it on your own, the fundamentals don't stick into your head.

Articles like this http://www.sommarskog.se/dynamic_sql.html are also extremely helpful, since they provide insight into how, why and why not.

Also check out this link http://www.sql-server-performance.com/tips/related_web_links_p1.aspx

Prashanth
this generally works, but I found that for my hobby projects, even ones that involve the database, most of my time is spent in the application layer instead of the database layer. Perhaps the problem is that my project is not database centric enough. In any case, I still want exercises, nothing like putting the nose to the grindstone and pounding out query after query after query.
MedicineMan
+1  A: 

sql-ex is very userful site to learn sql.

dotneter
A: 

If you have Reporting Services handy, or even Visual Studio, creating a few reports with aggregates, sums, counts etc will give you a little insight to how data can be used as information and really boost your SQL skills.

I work in a telephony company where this goes on all the time. I have this book sitting on my desk which I have found really handy.

Good luck! :)

Chalkey
I'm not familiar with Reporting Services. What are they? What's the difference between a report and a query?
MedicineMan
+2  A: 

A few things to focus on that will exercise a lot of areas of SQL that you should know if you're going to be writing a lot of it:

  • Joins - INNER and OUTER (difference between LEFT and RIGHT JOIN)
  • GROUP BY clause and working with aggregate functions such as SUM, MIN, MAX, etc..
  • WHERE - for filtering records returned in a query
  • Subqueries - Subqueries and Correlated subqueries
  • CASE, COALESCE, BETWEEN, CONVERT, CAST functions/statements

Find a good data set and try to run some meaningful queries on it. Make sure you start with a problem you want to solve (i.e. what is the average order amount for people who live in WA in the Northwind database?).

jn29098
This is not the actual answer, if I found a set of exercises, it seems like they would exercise the above. I'm considering this as the answer.
MedicineMan
+1  A: 

For a few simple problems/exercises: http://caml2010.wordpress.com/2010/06/12/northwind-exercise/

caml