mysql replace the primary key

1, first create a data table table_test:
Create Table table_test (
`id` VARCHAR (100) the NOT NULL,
` name` VARCHAR (100) the NOT NULL,
a PRIMARY KEY ( `name`)
) ENGINE = MyISAM the DEFAULT the CHARSET = GB2312;
2 , if you find the primary key setting is wrong, should be the id is the primary key, but now the table has a lot of data, and then rebuild the table can not be deleted, can only change the table structure on this basis.
Drop the primary key
alter table table_test drop primary key;
then add the primary key
alter table table_test add primary key (id );
Note: Before increasing the primary key, you must first delete duplicate id.

Guess you like

Origin www.cnblogs.com/mianbaoshu/p/12015531.html