OriginalSunny Posted February 5, 2006 Share Posted February 5, 2006 Hi, i am fairly new to mysql. I need to add a new column to a table and it works fine when using the following command:alter table [i]table name[/i] add [i]column name[/i] int(10) first;however i wish to also make it the new primary key of the table and also to assign it an auto increment value. How do i go about doing this?? Thanks. Quote Link to comment Share on other sites More sharing options...
fenway Posted February 5, 2006 Share Posted February 5, 2006 Try the following:[code]alter table table name add column name int(10) unsigned first not null auto_increment, add primary key (first);[/code]Just make sure you remove any existing primary key index first. Quote Link to comment Share on other sites More sharing options...
OriginalSunny Posted February 5, 2006 Author Share Posted February 5, 2006 I have just tried that command and unfortunately it comes up with error in your sql syntax. anything else i can try?? Quote Link to comment Share on other sites More sharing options...
fenway Posted February 5, 2006 Share Posted February 5, 2006 Post the "SHOW CREATE TABLE" for the table in question -- it's possible that you already have a primary key, and need to drop it first. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.