How to add auto increment primary key based on an order of column?
问题 I need to add an auto increment id to an already existing table. I did: ALTER TABLE table_name ADD column_name INT NOT NULL AUTO_INCREMENT FIRST , ADD PRIMARY KEY (column_name) However, the auto numbering wasnt based on any particular column order. I want mysql to smartly put auto numbers based on the order of certain column. Is it possible? Most of the answers out there tell you how to add auto increment fields, not how to control those numbers in already existing table. 回答1: Add a new field