Notes for changing tables in mysql when auto-tuning is enabled

Source: Internet
Author: User
Tags table definition

Mysql may modify tables in multiple cases. If you want to add an auto_increment for a table to implement automatic entire table, you need to pay attention to some problems. Otherwise, some errors may occur.

For example, to create a table:

Create table people (peopleid smallint not null, name CHAR (50) not null );

To modify a table in mysql, add an auto_increment for the peopleid so that the table can be automatically scaled up. mysql always reports the 1075 error at the beginning, so I checked the mysql 1075 error,

Error: 1075 SQLSTATE: 42000 (ER_WRONG_AUTO_KEY)

Message: an incorrect table definition can contain only one auto column and must be defined as a primary key.

You need to add a primary key first.

Alter table people add primary key (peopleid );

Alter table people change peopleid smallint auto_increment;

In this way, the mysql table is successfully modified.

If no primary key is added, is it okay?

If no primary key exists, you can:

Alter table people change peopleid smallint auto_increment unique;

This is also possible. Here we should note that if the field type is not indicated in every modification at the beginning, an error will always be reported, so we should not declare the field type.

The above are the issues that need to be paid attention to when mysql modifies the table to achieve automatic integer length.

Statement for modifying fields in mysql

Exception error due to insufficient MySQL database resources

How to delete multiple tables in MySQL

How MySQL connects to remote SQL

MySQL cluster introduction and Configuration

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.