MySQL how to set up auto-increment primary keys

When the initial use of the MySQL database, or accustomed to using the Oracle database (no auto-increment primary key), many small partners do not know how to field is set in a MySQL database in the corresponding table increment primary keys, here to share with you solutions :

The first case: the use of statements when creating the table:

User table created here, the user id to the primary key to create a self-energizing:
Create Table user (
id int (32) Primary Key AUTO_INCREMENT,
username VARCHAR (50)
);

The second situation: After you create a table, a field as the primary key:

Suppose there is still created in the user table, then the user is not the id to the primary key of the self-energizing a primary key:
ALTER user the Add Table Primary Key (id);

I hope everyone has to help!

Guess you like

Origin blog.csdn.net/fallwind_of_july/article/details/90416418