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.
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
Update 2:
When you want to delete all companies execpt a few (like DAT), just use this:
This will delete all companies except DAT en DEMO.
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"'
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'
DELETE FROM CompanyDomainList WHERE CompanyDomainList.CompanyID = 'CEU'
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'
DELETE FROM DataArea WHERE DataArea.ID <> 'DAT' AND DataArea.ID <> 'DEMO'
DELETE FROM CompanyDomainList WHERE CompanyDomainList.CompanyID <> 'DAT' AND CompanyDomainList.CompanyID <> 'DEMO'