开发者

How do I generate a unique ID without using AUTOINCREMENT

开发者 https://www.devze.com 2022-12-29 06:09 出处:网络
I am exporting data from csv into mysql database, I want the database to generate a unique id for each imported record. I want t开发者_如何学JAVAo use the unique field in generating a receipt number i

I am exporting data from csv into mysql database, I want the database to generate a unique id for each imported record. I want t开发者_如何学JAVAo use the unique field in generating a receipt number in crystal report.

What would you suggest as the best way of doing this?


If you don't want to auto increment the only other way to virtually guarantee uniqueness is to use a GUID as the id.

I say "virtually" as there is a theoretical possibility that the same GUID could be generated twice, but it's effectively zero for all everyday uses. From the Wikipedia article:

The total number of unique keys (2128 or 3.4×1038) is so large that the probability of the same number being generated twice is extremely small, and certain techniques have been developed to help ensure that numbers are not duplicated.


Autoincrement is absolutely the right way to do this in MySQL, is there are good reason not to use it?

If you want something more like Oracle's sequences, you can use another table with an autoincrement column.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号