Leong
Leong

Reputation: 329

Duplicate records in database from POST method

I am writing an app that will send a POST request to insert a new record into the database. Every records inserted will have an epoch time so me to track when is the record inserted. So far everything works fine in the testing stage. However, when the app is released for some time, I noticed that there are duplicate records in the database (same epoch time), but not all records are duplicated (mostly are not duplicated). So, I am curious that how this could happen and is there any ways to handle this it would be better that there is no any duplicated records in the database.

Upvotes: 0

Views: 33

Answers (2)

Sergey Kopanev
Sergey Kopanev

Reputation: 1504

To avoid duplicates you should use epoch time as a unique field in your database. Most of the databases are allowed to enable that for one/many fields.

Check your database manual on how to enable that; then, you will have no duplicate records.

Upvotes: 0

Suraj Bhalerao
Suraj Bhalerao

Reputation: 31

To prevent duplicate records with the same epoch time in your database, use the epoch time in milliseconds and apply a unique constraint on the relevant column. This will ensure each record has a distinct timestamp, and the database enforces uniqueness.

Upvotes: 0

Related Questions