Now i have a table with Auto_increment id as Pri key, and exchange_id as key, How could I change the primary key to field [ticker]..?
MySQL – How to Change Table Auto Increment Primary Key
MySQL
Related Question
- Mysql – Foreign key part of composite primary key of new table
- Mysql – Changing primary key from varchar to int
- MySQL – Unable to Convert Primary Key to Auto Increment
- MySQL – How to Reconfigure Primary Key Columns
- MySQL InnoDB – How to Set Auto Increment Value Without Downtime
- Mysql – Partitioning with AUTO_INCREMENT primary key
Best Answer
The
auto_increment
field must be an index, or be the first column of one. If you try to just drop the primary key, MySQL will complain. You have to delete theauto_increment
property before moving it:If you want
id
to continue beingauto_increment
, you have to do also:Please make sure to create if with the right index (multiple, unique) and nullability (null, not null).
Please also note that, depending on the engine used and/or the queries to be performed, a character field for a primary key may be suboptimal.