If you're processing a dataset with related records, you'll want to process
deletes from the bottom up and then apply updates and inserts from the top
down.
For example, assume the following relations:
Customers
Contacts (of a customer)
Phones (of a contact)
Delete any phones, then any contacts, the any customers. Unless you cascade
deletes and then you only delete the Customer record.
Insert any Customers, any contacts, and then any phones.
Updates technically can happen either with the deletes or the insert unless
you alter primary keys in which case you either need to cascade udpates or
actually delete from the bottom up and insert from the top down.