Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I generate a unique ID without using AUTOINCREMENT

Tags:

sql

unique

I am exporting data from csv into mysql database, I want the database to generate a unique id for each imported record. I want to use the unique field in generating a receipt number in crystal report.

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

like image 929
Ibrahim Avatar asked Oct 27 '25 08:10

Ibrahim


1 Answers

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.

like image 129
ChrisF Avatar answered Oct 28 '25 23:10

ChrisF