Home  >  Article  >  Database  >  How to set auto-increment field in existing table in mysql

How to set auto-increment field in existing table in mysql

coldplay.xixi
coldplay.xixiOriginal
2021-01-07 11:39:216302browse

Mysql method to set auto-increment fields in an existing table: 1. Add a field, the code is [alter table xiami add id int;]; 2. Modify the field, the code is [alter tabel xiami change id id auto_increment].

How to set auto-increment field in existing table in mysql

The operating environment of this tutorial: Windows 7 system, mysql version 8.0.22, DELL G3 computer. This method is suitable for all brands of computers.

Related free learning recommendations: mysql video tutorial

mysql sets auto-increment in existing tables Field method:

Step 1: Add field

alter table xiami add id int;

Step 2: Modify field

alter tabel xiami change id id auto_increment not null primary key;

Question:

Records in the table The number is 3929966

Query OK, 3929966 rows affected (2 min 8.09 sec)
Records: 3929966  Duplicates: 0  Warnings: 0  
查看创建表命令时,auto_increment为3932618
>> show create table xiami;
...
ENGINE=InnoDB AUTO_INCREMENT=3932618 DEFAULT CHARSET=utf8

The above is the detailed content of How to set auto-increment field in existing table 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