PDA

View Full Version : Creating unique id (not primary or index) on empty rows


UD2006
10-21-2009, 01:41 PM
I have a form to add contact info to the mysql database, when added to the database every record gets a unique id (it's not the primary or index column, just a column I created).

This all works perfect.

But I also have a csv sheet with contact data, I know how to import it, but then the unique id is not added.

How can I "create" a php code that imports the records from the csv file to mysql and with that add a unique id to every record that is being imported.

I have no clue on doing that, so if someone could help me with that would be great.

Thanks in advanced.

Fumigator
10-21-2009, 05:16 PM
The primary index has to be unique by definition... is your primary index auto-increment? And then you have another column with a unique index built on it? You can't have two auto-increment columns, so if you really need two different columns to have uniqueness you'll have to come up with that uniqueness at the point where your CSV file is built.

Old Pedant
10-21-2009, 09:01 PM
you'll have to come up with that uniqueness at the point where your CSV file is built.
Or imported. You don't have to use MySQL tools to do the import. You could write your own code that would import and supply the unique id at the same time.

But it does seem like a pretty cumbersome process. Why not just use an auto_number field as the PK and be happy????