Deleting records in MSCRM 4.0

As many of you would be aware, when deleting records from MSCRM, the record itself isn’t removed from the SQL database straight away- instead the DeleteStateCode of the record in question is updated to ‘2’. There are a number of ways to forcing a delete of the row immediately (this may be necessary if you’re testing a heavy data import script for example).

One way is to write a SQL script to empty the database tables representing your entities, so to remove all Contacts, you’d run the following script (this is assuming there are no relationships with any other entity- eg, no Contact has a Parent Customer):

delete from ContactExtensionBase
delete from ContactBase

Another way is to either delete your records from the application (thus setting DeleteStateCode to 2) or updating records in the database manually using SQL to set DeleteStateCode to 2 and then running the script Bill Owens has put up on his blog: His script makes the CRM deletion job run immediately (after you restart the CRM Asynchronous service).

Finally, there is also the ScaleGroup Job Editor which is a nifty little tool that you run on the CRM server itself. The tool allows you to set how often you want the Deletion job to run (among other CRM jobs). More info and download from here.

I’m sure people have discovered other (and better) ways to bulk delete records from CRM.. please feel free to share them with me!