MySQL database changes the primary key self-increment and the problem occurs

Source: Internet
Author: User

1. Create a database:

Create DATABASE User (

UID int NOT NULL,

Username varchar (+) NOT NULL,

Password varchar (+) is not NULL.

Primary KEY (UID)

);

The primary key for the database created by the statement is user, but there is no setting to increment the field, and the first data starts at 0. An error occurs when inserting a second data into the database without specifying the UID. So how do you modify the field to make it self-increment?

Alert table User Modify UID int (4) Auto_increment primary key.

Input change statement will be reported: multiple primary key defined, duplicate definition of primary key error

The modified statement of the integer error is: Alert table user Modify UID int (4) auto_increment;

So the primary key uid is self-increment, and the database automatically modifies the UID field of the first record inserted, changing 0 to 1.

MySQL database changes the primary key self-increment and the problem occurs

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.