---
title: "Deleting contacts and interactions from the xDB"
slug: "deleting-contacts-and-interactions-from-the-xdb"
abstract: "How to delete contacts and interactions from the xDB."
---
# Deleting contacts and interactions from the xDB

In Sitecore 9.2 and later, you can delete a contact and all associated interactions, facets, and identifiers. Use this functionality to remove data that is no longer valuable to your business - for example, you may want to delete contacts that do not have any interactions from the past two years. The following video demonstrates how to find and delete inactive contacts:

Be aware that:

- Deleting a contact is different from [executing the right to be forgotten](https://doc.sitecore.com/xp/en/developers/105/sitecore-experience-platform/deleting-contacts-and-interactions-from-the-xdb.html#UUID-c2f0beed-83f8-1d94-a818-49e77b3ddef6_section-5c9defe3d3657-idm46265903150144 "Delete and the right to be forgotten").
- Starting with Sitecore 10.2, you use the [XConnect purging tool](https://doc.sitecore.com/xp/en/developers/105/sitecore-experience-platform/xconnect-purging-tool.html "xConnect purging tool") to delete a subset of interactions, or delete interactions without deleting the contact.
- Deleting a contact removes that contact's interactions, which affects aggregated data in the xDB Reporting database if you choose to rebuild.

    > [!note]
    > The xDB Reporting database will include deleted data until you [choose to rebuild](https://doc.sitecore.com/xp/en/developers/105/sitecore-experience-platform/rebuild-the-reporting-database.html "Rebuild the reporting database").

- Contacts that are deleted during an active session will be partially recreated by the tracker on session end.

The following example demonstrates how to delete a batch of two contacts:

```csharp
using System;
using System.Threading.Tasks;
using Sitecore.XConnect;
using Sitecore.XConnect.Client;

namespace Documentation
{
    public class DeleteContact
    {
        // Async example
        public async void ExampleAsync()
        {
            using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
            {
                try
                {
                    // Get contact
                    var referenceOne = new Sitecore.XConnect.ContactReference(Guid.Parse("A9812105-2D45-A612-82E6-34E6D7117DCB"));
                    var referenceTwo = new Sitecore.XConnect.ContactReference(Guid.Parse("B9814105-1F45-E611-82E6-34E6D7117DCB"));

                    Task<Sitecore.XConnect.Contact> contactTaskOne = client.GetAsync<Sitecore.XConnect.Contact>(referenceOne, new ContactExecutionOptions(new ContactExpandOptions() { }));
                    Task<Sitecore.XConnect.Contact> contactTaskTwo = client.GetAsync<Sitecore.XConnect.Contact>(referenceTwo, new ContactExecutionOptions(new ContactExpandOptions() { }));

                    Contact contactOne = await contactTaskOne;
                    Contact contactTwo = await contactTaskTwo;

                    // Delete contact
                    client.DeleteContact(contactOne);
                    client.DeleteContact(contactTwo);

                    await client.SubmitAsync();
                }
                catch (XdbExecutionException ex)
                {
                    // Manage exceptions
                }
            }
        }

        // Sync example
        public void Example()
        {
            using (Sitecore.XConnect.Client.XConnectClient client = Sitecore.XConnect.Client.Configuration.SitecoreXConnectClientConfiguration.GetClient())
            {
                try
                {
                    // Get contact
                    var referenceOne = new Sitecore.XConnect.ContactReference(Guid.Parse("B9814105-1F55-E611-12E6-22E6D7117DCB"));
                    var referenceTwo = new Sitecore.XConnect.ContactReference(Guid.Parse("DB814105-1F45-E611-82E6-34E6D7117DCB"));

                    var contactOne = client.Get<Sitecore.XConnect.Contact>(referenceOne, new ContactExecutionOptions(new ContactExpandOptions() { }));
                    var contactTwo = client.Get<Sitecore.XConnect.Contact>(referenceTwo, new ContactExecutionOptions(new ContactExpandOptions() { }));

                    // Delete contact
                    client.DeleteContact(contactOne);
                    client.DeleteContact(contactTwo);

                    client.Submit();
                }
                catch (XdbExecutionException ex)
                {
                    // Manage exceptions
                }
            }
        }
    }
}
```

## Contact delete logic

When you delete a contact:

- The following data is removed from the xDB Collection database:
    - Interaction facets
    - Interactions
    - Contact facets
    - Contact
    - Contact identifier indexes

    > [!note]
    > Device profiles associated with the contact are not removed.

- The xDB Search Indexer removes all contact and interaction data from the xDB index.
- The Marketing Automation Engine's xConnect service plugin (`Sitecore.XConnect.Service.Plugins.MarketingAutomation.XdbContactEventWatcher`) adds a high priority work item to remove the deleted contact from all automation plans.

Keep the following in mind when using the delete operation:

- The delete operation ignores concurrency token validation. This means that the contact will be deleted even if it is being updated by a parallel thread, and contact identifiers are deleted even if the contact identifier index is locked.
- The delete operation is transactionless, which may result in data being partially deleted if a system error occurs at the provider level (SQL).

### Delete and merged contacts

When two contacts are merged, references are added between the source and target contact. The target contact references the source contact via a merge identifier, and the source contact references the target contact via a facet property.

A contact that has been part of multiple merge operations results in a merge tree of related contacts. In the following diagram, *Known2* is the target of several merge operations and the current root of the merge tree:

> [!note]
> The example uses text identifiers instead of GUIDs for readability.

![merge-and-delete.PNG](https://doc.sitecore.com/api/markdown-image/xp/en/developers/105/sitecore-experience-platform/images/merge-and-delete.PNG)

Sitecore 9.2 and 9.3 differ slightly in how the following scenario are handled:

- Deleting a contact in the middle of the merge tree (for example, *Known1*).
- Deleting the root contact (for example, *Known2*).

#### Delete and merged contacts in 9.2

In Sitecore 9.2, the following logic applies when you delete a contact:

- If you delete a contact in the middle of the merge tree (for example, *Known1*), you break the chain that links *Known2* with *Anon1* and *Anon2*. *Anon1* and *Anon2* become orphans.
- If you delete the root contact, no other contacts are deleted. The contacts marked *Obsolete* in the diagram remain in the xDB Collection database.

#### Delete and merged contacts in 9.3 and later

In 9.3 and later, the following logic applies when you delete a contact:

- If you delete a contact in the middle of the merge tree (for example, *Known1*), new references are created between the root contact and the remaining contacts in the branch. In the following example, references are added between *Known2* and *Anon1*/*Anon2*.

    ![merge-and-delete-2.PNG](https://doc.sitecore.com/api/markdown-image/xp/en/developers/105/sitecore-experience-platform/images/merge-and-delete-2.PNG)

- If you delete the root contact, the entire merge tree is deleted. This means that deleting *Known2* also deletes *Anon1*, *Anon2*, *Anon3*, and *Known1*.

## Delete and the right to be forgotten

Deleting a contact is not the same as [using xConnect's right to be forgotten feature](https://doc.sitecore.com/xp/en/developers/105/sitecore-experience-platform/execute-right-to-be-forgotten.html "Execute right to be forgotten"). Your organization must decide which option meets the requirements for GDPR and other data privacy legislation in your particular case.

> [!warning]
> Be aware that contacts that are deleted during an active session will be partially recreated by the tracker, including any known or anonymous identifiers.