Home > Database > Mysql Tutorial > body text

How to modify and add primary key in mysql

王林
Release: 2020-10-19 10:57:49
Original
4624 people have browsed it

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
Copy after login

Modify the primary key

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

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`);
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template