Adding a minimum length constraint in SQL Server

This might seem fairly obvious, but using Len(ColumnName) can give unexpected results, as it returns the number of characters in a string instead of the number of bytes, i.e. it trims the text before it counts the characters. More details on that here. To create a minimum length constraint, open up your table, right click Constraints and select New Constraint. Then enter something like… (datalength([YourColumn])>(2))…

Read More

SQL Server 2005 maintenance plan fails and service pack fail to install

I needed to setup a maintenance plan for a client to backup their databases and remove backups older than 4 weeks. They run SQL Server 2005, so I created the maintenance plan with a Back Up Database Task and a Maintenance Cleanup Task to remove the old backups, which is straightforward enough. When I tried to test it however I got the error: **“Unable to start execution of step 1 (reason: line(1): Syntax error). The step failed." ** I had a quick look at the version of the server and it was 9.…

Read More