简体   繁体   中英

MySQL: create table, primary key automatically generated?

In mysql, how do I automatically generate primary key for a table?

If I don't specify a primary key in,

CREATE TABLE my_table(
   ...
   ...
);

would mysql automatically generate primary key?

No, if you don't specify a primary key it will not create one. To create a primary key, use the following.

CREATE TABLE my_table(
   id int NOT NULL,
   PRIMARY KEY (id)
);

This will create an "id" column, make it not null, and the primary key.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM