Work-around for 2005 Maintenance Plan bug

In working with SQL 2005 Maintenance Plan backup cleanup tasks, a frustrating bug was found. It seems that when the ability to select “hours” as a time criterion was added in SP2, the door was opened for misinterpretation of time units. For example, you can, in your local Management Studio, set the Plan to delete files greater that 4 days old, and when run on the server the Plan will delete files only greater than 4 WEEKS old. This was the full mapping I found:

SET ACTUAL
Hours -> Days
Days -> Weeks
Weeks -> Months
Months -> Years
Years -> Years

I don’t know yet if this is fixed in 2008. For 2005 at least, I suggest refraining from using the built-in “Maintenance Cleanup Tasks” in Maintenance Plans, and instead use a T-SQL Statement task with the snippet below. This will truly delete greater than 4 days. Set your time criteria however you like.

DECLARE @DateOlderThan datetime
SET @DateOlderThan = DATEADD(day,-4,GETDATE())

EXEC master.dbo.xp_delete_file
	 0						-- delete files
	,N'H:\SQLBackup\INST3'	-- full path to the main directory
	,N'bak'					-- file extension
	,@DateOlderThan			-- delete files created before this timestamp
	,1						-- Including first-level sub

Advertisements

“Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created.”

Management Studio 2008 has a default that prevents saving table changes from the designer when the table will need to be rebuilt. I’m constantly being asked about this error by developers:

“Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created.”

To be able to make table changes go to Tools->Options->Designers and uncheck “Prevent saving changes that require table re-creation”.

It’s a good idea to do this as soon as you install 2008. Tell everyone around you. I’m asked about it quite often.