How to prevent duplicate data added into the database?

How do i prevent the same data from being duplicated when i add it into the database? I have these 2 fields.

Example if i key in 938474 as the NRIC and 01983742 as the contact number, it will be stored in the database. If i key in 938474 as the NRIC and 01983742 as the contact number again, I want the data to not duplicate in the database as the same data is already stored inside. This is the Submit function. How do i ensure that there will be no duplicate in the database? 

Hello Jack

The easiest way is:

  • Go to Entity.
  • Choose Edit Entity
  • Find the Indexes tab.
  • Create an Index over that field saying Unique=Yes. If you make a single index over both fields, only the exact pair will be blocked, both values are allowed with different pairs).
  • This way, the database will prevent saving duplicate values.
  • It will return an error that you must handle.

The other way is before saving, search for that value and warn the user if it is repeated.

Ideal way: use both.

Hi Nuno Reis,

Is there any other way to be able to submit the duplicated data and cause no error in the webpage but the data will not be stored in the database since it is duplicated?



Hi Jack,

you can do it by  filter by your inputs.

When you are submitting data before check in entity with all inputs if aggreagte return data that mean same data has been present else you can save data. and their is not exception occure.

But you need to ensure filters are proper.

Regards

Rahul Sahu

Jack Lin wrote:

How do i prevent the same data from being duplicated when i add it into the database? I have these 2 fields.

Example if i key in 938474 as the NRIC and 01983742 as the contact number, it will be stored in the database. If i key in 938474 as the NRIC and 01983742 as the contact number again, I want the data to not duplicate in the database as the same data is already stored inside. This is the Submit function. How do i ensure that there will be no duplicate in the database? 

Hi

you can double click the entity and go to indexes tab --> new index--> name of the index and add the attributes you want to be unique,

Here you can't add same name on same address

Hope this helps you

Thanks 

Shehroze khan

Jack Lin wrote:

Hi Nuno Reis,

Is there any other way to be able to submit the duplicated data and cause no error in the webpage but the data will not be stored in the database since it is duplicated?

It is all up to how you develop it and how you choose to inform.

If you handle the error and don't show any message, the user will not know something caused an error.

Saying nothing is easier than notifying the user so if you can do it, go for it:) 

The index is the guarantee that the record won't be duplicated.

While saving data first you have to check data based on the filter. - use aggregate and apply the filter on both columns using your entered values


If data exists don't save simply skip to next step

If not then save data.


Jack Lin wrote:

Hi Nuno Reis,

Is there any other way to be able to submit the duplicated data and cause no error in the webpage but the data will not be stored in the database since it is duplicated?

Hi Jack,

Like Nuno said:

The other way is before saving, search for that value and warn the user if it is repeated.

So if you search for those values using an aggregate, you would not necessarily need to raise an error (and certainly no Database error would occur like when using a unique index). In case a record with both fields already exists, you could just simply use a Feedback Message for example to let the user know he can't add that record.

Hope this helps!

Regards,

Nordin


Jack Lin wrote:

Is there any other way to be able to submit the duplicated data and cause no error in the webpage but the data will not be stored in the database since it is duplicated?

Hi Jack,

The easiest way to do this is:

1) Before saving in the DB (CreatContacts node), you can execute an aggregate over your entity and verify if you have any records with NRIC =  938474 (your input) and Contact Number = 01983742 (your input).

2) If the aggregate returns empty, then you keep the flow and advance to the CreatContacts node and that record will be created since it doesn't exist in DB.

3) If the aggregate returns a row, this means that the record already exists. Then you just need to skip the create and go directly to the page MainFlow\CoronaVirus. This way you will avoid duplicated data and still cause no errors in the webpage.


Kind regards,

Rui Barradas