We had to write Pascal interpreter in Prolog - that was an experience. I strongly suggest to everybody to try Prolog - then you will understand why it is good idea to use declarative languages as much as possible when building product (including SQL).
http://www.amazon.com/Prolog-Programming-Artificial-Intellig...