How to mass delete all company?

Hi all,

I wanted to mass delete all company because it is duplicated after import from sage, and would like to start a new. but I do not want to replace with a new database because of the other valuable data such as users, workflows etc. I just want to remove all company.

So far I only found a way to remove company one by one and its slow. How can I remove/delete all company at once?

thank you

  • 0

    Hi Murni

    Do you mean to completely empty it of data (not settings)? I do this for customers where they have a test environment and then I have a big Truncation script that goes through all the tables and clears out the data within them, but leaves behind all settings. 

    There are some important questions here - are you linked to an ERP system? If so which one, I'm coming at this from the UK where we have Qnect linking to Sage 200. (Would need to adjust it for the old Classic Integration) Otherwise if linked to something else, you might need to investigate it a bit more to know what other tables to either delete from (because you don't want to empty the entire table but get right of certain rows) or to truncate (to wipe clean)

    TRUNCATE TABLE Account
    TRUNCATE TABLE AccountProgress
    TRUNCATE TABLE Activity
    TRUNCATE TABLE Address
    TRUNCATE TABLE Address_Link
    TRUNCATE TABLE CallList
    TRUNCATE TABLE CallListTracker
    TRUNCATE TABLE Campaigns
    ​TRUNCATE TABLE Cases
    TRUNCATE TABLE CaseProgress
    TRUNCATE TABLE Communication
    TRUNCATE TABLE Comm_Link
    TRUNCATE TABLE Company
    TRUNCATE TABLE CRMEmailPhoneData
    TRUNCATE TABLE EmailLink
    TRUNCATE TABLE Forecast
    TRUNCATE TABLE ForecastHistory
    TRUNCATE TABLE Journal
    TRUNCATE TABLE Lead
    TRUNCATE TABLE LeadProgress
    --TRUNCATE TABLE Library
    TRUNCATE TABLE Marketing
    TRUNCATE TABLE NewProduct
    TRUNCATE TABLE Notes
    TRUNCATE TABLE Opportunity
    TRUNCATE TABLE OpportunityProgress
    TRUNCATE TABLE OrderItems
    TRUNCATE TABLE Orders
    TRUNCATE TABLE Person
    TRUNCATE TABLE Person_Link
    ​TRUNCATE TABLE PhoneLink
    TRUNCATE TABLE Pricing
    TRUNCATE TABLE PricingList
    TRUNCATE TABLE ProductFamily
    TRUNCATE TABLE QuoteItems
    TRUNCATE TABLE Quotes
    TRUNCATE TABLE Rep_Deletes
    TRUNCATE TABLE Solutions
    TRUNCATE TABLE SolutionsProgress
    TRUNCATE TABLE TaxCode
    TRUNCATE TABLE UOM
    TRUNCATE TABLE Warehouse​
    TRUNCATE TABLE WaveItem_Email
    TRUNCATE TABLE WaveItem_Schedule
    TRUNCATE TABLE WaveItem_Users
    TRUNCATE TABLE WaveItems
    TRUNCATE TABLE Waves

    /* For Qnect200
    TRUNCATE TABLE QnectCompany
    TRUNCATE TABLE QnectFinancials
    TRUNCATE TABLE QnectNominalCode
    TRUNCATE TABLE QnectSystemLinks
    TRUNCATE TABLE WarehouseHoldings
    -- DELETE FROM QnectSystem WHERE qnsy_type = 'Dataset' -- This one removes the integration but keeps the main record
    */

    DELETE FROM Email
    DELETE FROM Phone
    DELETE FROM Library WHERE Libr_FilePath NOT LIKE 'Global Templates\UK\%'  --Only delete and not Truncate because I want to keep the UK templates and not have to reupload them. 

  • 0 in reply to Matthew Shaw

    Hi Matthew,

    yes, I want to completely empty the company data. Initially, Sage CRM is used for testing and training end user & already have company data. Then, I am importing customer and vendors from Sage 300 for testing. Now it have double entry of the same company, the original and the imported one, and kind of messy too. 

    thank you for the script, will try it out and check on the Sage 300 side as well.