Skip to main content

Posts

Showing posts from February, 2010

Building a Simple Data Definition DSL with Boo

In my daily work, I find myself writing a lot of one-off SQL scripts to handle various data issues. In particular, I've had to tweak existing sets of metadata with scripts that look something like the following: DECLARE @SomeId INT DECLARE @SomeOtherId INT SELECT @SomeId = SomeTableId FROM SomeTable WHERE SomeName = 'Something' SELECT @SomeOtherId = SomeOtherTableid FROM SomeOtherTable WHERE SomeOtherName = 'SomethingElse' IF NOT EXISTS( SELECT 1 FROM SomeMetadataTable WHERE Name = 'MetadataName') BEGIN INSERT INTO SomeMetadataTable (Name, Property1, Property2) VALUES ('MetadataName', @SomeId, @SomeOtherId) END ELSE BEGIN UPDATE SomeMetadataTable SET Property1 = @SomeId , Property2 = @SomeOtherId WHERE Name = 'MetadataName' END Just writing a few of these gets to be tedious, and master script