poleposters Posted December 19, 2009 Share Posted December 19, 2009 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 Link to comment https://forums.phpfreaks.com/topic/185670-create-a-unique-key-column-after-the-database-has-been-populated/ Share on other sites More sharing options...
taquitosensei Posted December 19, 2009 Share Posted December 19, 2009 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. Link to comment https://forums.phpfreaks.com/topic/185670-create-a-unique-key-column-after-the-database-has-been-populated/#findComment-980394 Share on other sites More sharing options...
roopurt18 Posted December 19, 2009 Share Posted December 19, 2009 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; Link to comment https://forums.phpfreaks.com/topic/185670-create-a-unique-key-column-after-the-database-has-been-populated/#findComment-980395 Share on other sites More sharing options...
The Little Guy Posted December 19, 2009 Share Posted December 19, 2009 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! Link to comment https://forums.phpfreaks.com/topic/185670-create-a-unique-key-column-after-the-database-has-been-populated/#findComment-980403 Share on other sites More sharing options...
poleposters Posted December 19, 2009 Author Share Posted December 19, 2009 Thanks all. Solved! Link to comment https://forums.phpfreaks.com/topic/185670-create-a-unique-key-column-after-the-database-has-been-populated/#findComment-980412 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.