Home  >  Article  >  Database  >  How to modify and add primary key in mysql

How to modify and add primary key in mysql

王林
王林Original
2020-10-16 10:49:264587browse

Mysql Modify the method of adding a primary key: Execute the [ALTER TABLE `test2` DROP PRIMARY KEY, ADD PRIMARY KEY (`id`);] statement to modify the primary key.

How to modify and add primary key in mysql

Add table fields

(Recommended tutorial: mysql video tutorial)

alter table table1 add transactor varchar(10) not Null;
alter table   table1 add id int unsigned not Null auto_increment primary key

Modify the primary key

ALTER TABLE `test2` DROP PRIMARY KEY ,ADD PRIMARY KEY ( `id` )

Increase index

ALTER TABLE `test2` ADD INDEX ( `id` )
ALTER TABLE `category ` MODIFY COLUMN `id`  int(11) NOT NULL AUTO_INCREMENT FIRST ,ADD PRIMARY KEY (`id`);

Related recommendations: mysql tutorial

The above is the detailed content of How to modify and add primary key in mysql. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn