views:

199

answers:

2

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?

+1  A: 

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.

Colin Pickard
+2  A: 

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.

ChrisF
Thanks, i would go with the auto_increment function. But i need to know if it would automatically generated IDs if i use the LOAD DATA INFILE command. Also i need to know how to fix the number of digits that appears. i want to convert the numbers to HEX using the hex(id) function, but i want the hex value show in a block of 6. ABCDEF.
Ibrahim