I have encountered a problem in that I already have a composite primary key in a MYSQL table. But now I have added another column to that table and due to some requirement changes, I have to modify that composite primary key in such a way that I need to add that previously mentioned column to that composite primary key list. Can anyone tell me how to alter that table without dropping existing composite primary key. I am doing this in a Rails project
+1
A:
You can't alter the primary key. You have to drop and re-add it:
ALTER TABLE MyTable
DROP PRIMARY KEY,
ADD PRIMARY KEY (old_col1, old_col2, new_col);
Jeremy Stein
2010-02-25 16:50:07