Code Persona

January 2008 Entries

Tool To Quickly Version Control / Reverse Engineer Your Database

Jeff Atwood, in his blog post strongly recommends taking your database to source control. He mentions:
The database is a critical part of your application. If you deploy version 2.0 of your application against version 1.0 of your database, what do you get? A broken application. And that's why your database should always be under source control right next to your application code. You deploy the app, and you deploy the database. Like peanut butter and chocolate, they are two great tastes that taste great together.
In the past we’ve scripted our databases using the Visual Studio Database project and hand written our DDL and DML script for the data model and the default data.
Microsoft SQL Server Database Publication Wizard has the capability of generating your SQL scripts from your database so that you don’t have to write these manually.
Of-course Management Studio can do this as well but where this tool really scores is in it’s ability to generate the DML for data in the tables as well if you want it to.
This means now you can create your database and fill dummy data into it using Management Studio, then fire this tool, point it to this database and you get a ready to use SQL script which you can version control.
With a free tool to take your database to SVN and very little effort needed to achieve this, there is no reason why you shouldn’t keep your database in your SVN now.
So, is your database under version control? If not, go ahead, try this database. If you are manually writing your DDL and DML script for database schema and default data this tool might save you a lot of time as well.  
 

Think LINQ with LINQPad - The SQL Analyzer of LINQ

Soren in his post expresses his desire for finding the SQL Query Analyzer equivalent of LINQ. He states:
If you haven't picked up on it yet I can tell you that I' very excited about LINQ at this point. Now all I need is for someone to create Query Analyser for LINQ for me and I'm good to good. What's even more interesting about such a tool is the fact that you would be able to target not just SQL but all the supported data store, although the queries wouldn't be interchangeable
Turns out, Soren is in luck.
LINQPad isn’t exactly a Query Analyzer but it does for LINQ programmers pretty much what Query Analyzer did for SQL Programmers.
It allows you to hook on to any SQL database and fire LINQ statements much like you would have fired SQL statements in Query Analyzer.
The authors of LINQPad give very valuable advice if you are genuinely interested in learning LINQ and getting into the LINQ way of thinking:
The rules are simple:
  1. Locate the shortcut for SQL Management Studio on your Start Menu and move it some place else.
  2. In its place, insert a shortcut to LINQPad.
  3. For the next week, perform all your ad-hoc SQL queries using only LINQPad.
At the end of the week, you will actually think in LINQ, rather than thinking in SQL and translating to LINQ.
It’s a single executable; it hooks on to both SQL Server 2005 and SQL Express and allows you not just practice LINQ but adapt to the LINQ way of thinking.
Give LINQPad a shot. Very soon you will genuinely start writing LINQ much like you write SQL, instead of thinking SQL and then attempting to translate it to LINQ.