Monday, November 17, 2008

The importance of SQL Check Constraints

Not long ago I developed a database that was missing the proper check constraints on the columns. During the development of the application this was not a problem because I was doing all of the validation in the application. For example, I was checking that phone numbers and zip codes all used the same formats. The application was base on Volunteers and Events so searches against the database were based on fields such as phone numbers and zip codes to find volunteers. After the application was implemented into production all was going well until they noticed that many volunteers with matching phone numbers and zip codes were not coming back in the searches. I found out later that backend imports were being performed against the database. The import program had phone numbers and zip codes that were formatted differently. When the SQL Query was executed it was looking for a phone number in the format of ‘(888)222-2222’. Although the volunteer existed in the database, the phone number was formatted such as this: 888-222-2222 and the records were not returned. If I would have put the proper check constraints on my phone number and zip code columns this would not have been a problem.

http://msdn.microsoft.com/en-us/library/ms179491.aspx

Wednesday, November 5, 2008

A fast and easy console shell - Part 2

In part one I talked about how to build a fast and easy console shell. In part two, I want to talk about how to handle parameters that are passed in the command (well not passed in). Using this type of shell, I see no reason why parameters need to be passed in with the command. For example, the command “Start service ‘servername’”. The runtime needs to find where the base command ends and where the parameters start. Also, there is that problem of parameter ordering. I found, that the best way to handle this, is do just use “Console.ReadLine()”. For example,

public void Exeucte()

{

     Console.WriteLine( “Service to start:”);

     string serviceName = Console.ReadLine();

     StartService( serviceName );

}

Pretty easy! This way also allows you to enter and display defaults in case the user does not enter a value or just wants to use the default.