Jump to content

Create a unique key column after the database has been populated


poleposters

Recommended Posts

Hi,

 

I've been using phpmyadmin to import a csv file containg data for 10 columns. And only after the fact have I realised that I need a unique key column at the beginning of the table.

 

Is this possible through phpmyadmin?

 

Thanks.

 

matt

Create a table like your table but with an auto increment column.  Then insert the data from your original table into it.  Drop the original table. Create a table with the original name like your second table. Then insert the data into it.

I suspect you could but I don't know for sure.

 

What you can do to test though, is to create a duplicate table with a different name.  You can do something like "CREATE TABLE mytesttable LIKE myexisting table;" refer to the MySQL documentation for details.

 

Then you can do "INSERT INTO mytesttable SELECT * FROM myexistingtable WHERE 1=1;"  Again, see the MySQL documentation for particulars.

 

Now that your test table is populated, you can mess around with it any way you want to.  Add new columns and see what happens.

 

When you're done, eliminate the test table: DROP TABLE mytesttable;

yes...

 

Do this

 

1. Choose table (Structure view, second tab)

2. Find: "Add ... field(s)"

3. Check the radio that says "At beginning of table"

4. Click "GO"

 

5. Give the field a name

6. Change the type to smallint, int, bigint, etc...

7. Check the first radio button "Primary"

8. Change Extra to "AUTO_INCREMENT"

9. Press "Save"

 

That should add the column to the beginning of the table with the increments starting at 1 and incrementing by one for each field.

 

Hope this helps!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.