简体   繁体   English

MySQL:创建表,自动生成主键?

[英]MySQL: create table, primary key automatically generated?

In mysql, how do I automatically generate primary key for a table? 在mysql中,如何自动为表生成主键?

If I don't specify a primary key in, 如果我没有在其中指定主键,

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

would mysql automatically generate primary key? mysql会自动生成主键吗?

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. 这将创建一个“ id”列,使其不为null,并创建主键。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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