An erp consultant asked me to remove all customers (persons) from a test site along with associated data like org links etc. Basically reset the customer module. They have a LOT of customers so manually doesn’t work.
I’m looking for a db script for this and would be grateful for one
DELETE FROM Security.PasswordLoginInfo WHERE NOT SystemId IN ('00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000002')
DELETE FROM Customers.PersonOrganizationLinkRoles WHERE NOT PersonSystemId IN ('00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000002')
DELETE FROM Customers.PersonOrganizationLink WHERE NOT PersonSystemId IN ('00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000002')
DELETE FROM Customers.PersonGroupLink WHERE NOT PersonSystemId IN ('00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000002')
DELETE FROM Customers.PersonFieldData WHERE NOT OwnerSystemId IN ('00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000002')
DELETE FROM Customers.PersonAddress WHERE NOT OwnerSystemId IN ('00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000002')
DELETE FROM Customers.Person WHERE NOT SystemId IN ('00000000-0000-0000-0000-000000000001', '00000000-0000-0000-0000-000000000002')
The excluded GUIDs are for the system and everyone user.