Monthly Archives: May 2012

Delete an AX company on SQL

Here a nice little SQL statement that uses the sp_MSforeachtable stored procedure to delete all records of a specific company (CEU in this case) from all tables.

EXEC sp_MSforeachtable ‘delete from ? where ?.DataAreaID = “CEU”‘

Certainly fast(er than AX) and gets the job done.
Use at your own risk 😉

You’ll want do do some cleaning up to:
delete the company id from the DataArea table and from the CompanyDomainList table

DELETE FROM CompanyDomainList WHERE CompanyDomainList.CompanyID = ‘CEU’

Update 2:
When you want to delete all companies execpt a few (like DAT), just use this:

EXEC sp_MSforeachtable ‘delete from ? where ?.DataAreaID <> “DAT” AND ?.DataAreaID <> “DEMO”‘
DELETE FROM DataArea WHERE DataArea.ID <> ‘DAT’ AND DataArea.ID <> ‘DEMO’
DELETE FROM CompanyDomainList WHERE CompanyDomainList.CompanyID <> ‘DAT’ AND CompanyDomainList.CompanyID <> ‘DEMO’

This will delete all companies except DAT en DEMO.

Leave a comment

Posted by on May 31, 2012 in Uncategorized