# Detect duplicate primary keys

As the uniqueness of the primary key is really important to guarantee optimal DinMo operation, we will help you check the level of duplication:

* When creating the model
* Once a day, after model creation
* On demand by consulting your model

To calculate the percentage of unique primary keys, DinMo uses the following formula:

```
percentage = (count(distinct primary key) / count(primary key)) * 100
```

This formula divides the number of distinct primary keys by the total number of primary keys, then multiplies by 100 to get the percentage.

### At model creation

When you create a model and click "Save," a pop-up will appear, allowing you to verify the percentage of duplicate primary keys within the model.

There are three possible scenarios: the primary key is unique, the duplicate rate is low or the duplicate rate is too high.

#### No duplicate primary keys

DinMo checks that the primary key you've selected is unique, i.e. that the percentage of unique primary keys is 100%.

In that case, you are directly invited to save the model.

<figure><img src="https://3204318043-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxzBTp1t4OfqV67nXkVse%2Fuploads%2FDeHLokJugJC94LX3IcGx%2Fimage%20(31).png?alt=media&#x26;token=c8aa0308-7cb0-4ecf-bd0a-3758e10bfb7c" alt=""><figcaption><p>Primary key is unique - You can save the model</p></figcaption></figure>

#### The duplicate rate is low

This is the case if the rate of non-unique primary keys is less than 5%. In this case, DinMo alerts you that your model may have a problem.

<figure><img src="https://3204318043-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxzBTp1t4OfqV67nXkVse%2Fuploads%2FJldAlA9HbG4Hv1xLyzxd%2Fimage%20(32).png?alt=media&#x26;token=e56e63e4-cd24-4638-a747-638e4fa0bf2f" alt=""><figcaption><p>Primary key is not unique but duplicate rate is still low</p></figcaption></figure>

:warning: You can save your model this way, but we **strongly recommend that you correct your source data** to restore a duplicate rate equal to 0%.

If you leave your duplicate rate above 0%, the situation is likely to worsen over time, affecting DinMo's operations. Don't worry, you'll be alerted anyway if this becomes the case, thanks to our **daily checks**.

If you decide to leave your duplicate rate above 0%, we'll also alert you in your model overview.

<figure><img src="https://3204318043-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxzBTp1t4OfqV67nXkVse%2Fuploads%2FhNpblhraJ0MYh46pkgj0%2FCapture%20d%E2%80%99e%CC%81cran%202025-01-27%20a%CC%80%2014.23.37.png?alt=media&#x26;token=63b5b71f-351f-4795-9c56-d2cfe929ab0d" alt=""><figcaption><p>Alert on the model - Duplate primary keys detected</p></figcaption></figure>

#### The duplicate rate is too high

If your duplicate rate is higher than 5%, you won't be able to register your model in DinMo.

<figure><img src="https://3204318043-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxzBTp1t4OfqV67nXkVse%2Fuploads%2FZergvkSOEzugGWrVaeVA%2Fimage%20(34).png?alt=media&#x26;token=a88bcf30-2c9f-43ed-b87e-b719ecc0a570" alt=""><figcaption><p>Duplicate rate is too high - You can't save the model</p></figcaption></figure>

You then have several options for correcting your problem:

* Go back to the configuration and choose an other primary key (e.g. *customer\_id* instead of *last\_name*)
* Modify your table structure / clean your data directly from your source, to ensure unique primary

You can then re-click on “Check duplicate primary key”. If the duplicate rate falls below 5%, the warning will disappear and you will be able to save your model.

### Daily checks

To ensure that the duplicate rate remains low over time, DinMo performs automatic checks every day.

If the primary key remains unique (0% duplication), there will be no impact on your model — and therefore on the associated objects.

On the contrary, if DinMo detects that the primary key is not unique, you will be alerted and a warning message will appear on your model:

<figure><img src="https://3204318043-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxzBTp1t4OfqV67nXkVse%2Fuploads%2FUTag0AmcfBl2JuVMYJNB%2FCapture%20d%E2%80%99e%CC%81cran%202025-01-27%20a%CC%80%2014.20.39.png?alt=media&#x26;token=48f4f36b-c18d-4109-9100-7d86ef1057be" alt=""><figcaption><p>No duplicate then a lot: warning message</p></figcaption></figure>

In that case, you'll need to update your table directly in your data warehouse. Cleaning your data will ensure that the duplicate rate remains as close to 0% as possible.

When the changes have been made, you can click on “Check duplicate primary key” again. If everything has been done correctly, your alert message will disappear.

### Manual check

If you've made changes to your data warehouse and want to make sure that this doesn't impact the duplicate rate in your model, you can check this directly in DinMo.

To do so, directly go to your model and click on "..." at the top right of your page:

<figure><img src="https://3204318043-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FxzBTp1t4OfqV67nXkVse%2Fuploads%2F8OYj5RTph9Af44qTROHk%2FCapture%20d%E2%80%99e%CC%81cran%202025-01-27%20a%CC%80%2014.16.55.png?alt=media&#x26;token=2ab81730-c136-4222-8275-d2a4f559addf" alt=""><figcaption><p>Manually check duplicates by clicking on "Check duplicates"</p></figcaption></figure>

A new pop up will open and update the percent of duplicate primary keys. DinMo will then display the warning and the associated error if needed.
