Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

How can I automatically ensure that each record receives a unique primary key?

0
Posted

How can I automatically ensure that each record receives a unique primary key?

0

mSQL version 1.x does not have an automatic key assignment functionality. A number of solutions to this problem are available. • Use Pascal Forget’s unique sequence number generator. • Build the unique key assignment and management into your application. One suggestion on how to implement this comes from Vivek Khera . Vivek writes: What I do is take some of the fields in the record, tack on a salt like the current time and generate a hash (either SHA or MD5) of it. I use part of the the hash string value as the key. Another solution is provided by Rasmus Lerdorf . Rasmus writes: The issue here is not so much how to generate a key, but how to ensure it is unique. The way I have done it in the past is to associate a lock file with each table. Each table has a counter record. With the table locked, I pull out the current counter value, increment it, and put it back. Then I unlock the table. This is not the most efficient way to do it, but it does wor

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123