Data duplication

Hello everyone,

I have an attribute in a table which is an unique number generated in an incremented way(+1 logic). But there are some scenarios where the timestamp of the two users matches and the same number is assigned to both the users. can you please tell a soln for this apart from indexing?

mvp_badge
MVP

Hi Sharon,

Can you explain a bit more what a timestamp had to do with users getting the same number? Do you mean you are determining the last number by a query, then adding 1, and this happens twice at the same time?

Dear Sharon

The best way to avoid data duplication with the IDs are to use Primary Key or the Attribute with Unique. 

You can set the Attribute Unique with the Index - 



Now, from your statement it seems you are using +1 login in timestamp? If the timestamp is same the same number is assigning... It seems you have added logic in incorrect way. Please try to evaluate or regenerate it with the above rule. 


Hi sharon sharon,

I would suggest while creating user record , read the last record´s unique number , increment it by 1 and insert for the new record.

Do not mix the logic of incrementing number and timestamp. Decouple both the activity and simply fetch the last number & insert ( last unique number +1).

Please give detail about your requirements if your use case does not support above solution so that we can suggest some other ideas or suggestions.

Thanks,

Vani


mvp_badge
MVP

Hi Vani,

That's a flawed approach, and probably what they already do, as that could cause the duplicates if two people (or two processes) are doing that at exactly the same time (I think that's what the OP means by "same timestamp"). 

To solve this, you could use a GetForUpdate Entity Action on some special Entity (that may also keep the last Id), then doing the incrementing logic.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.