Delete an AX company on SQL

February 3, 2010 at 21:03
filed under Dynamics AX
Tagged ,

This week, we were shrinking a database of a development environment by deleting some companies.
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 ;-)

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

DELETE FROM DataArea WHERE DataArea.ID = 'CEU'
DELETE FROM CompanyDomainList WHERE CompanyDomainList.CompanyID = 'CEU'

no comments

RSS / trackback

respond