There are two ways to create a primary key:
CREATE TABLE Table name (
Field Name Type,
Field Name Type,
......
Primary key (name)
);
or a
CREATE TABLE Table name (
Field Name Type primary key,
Field Name Type,
......
);
However, it is important to note that you cannot use the second method if you want to create a composite primary key.
Here is a small example:
Here is an error multiple primary key defined, which indicates that multiple primary keys are defined, and the correct wording is as follows:
If the key to set the composite primary key, the characteristics of the composite primary key is created at the same time, delete, so you need to delete the primary key, but here set the self-increment, you need to first remove the primary key, if you do not delete the auto-increment, and directly delete the primary key will be an error (as follows).
You need to delete the self-increment first:
Here we create the composite primary key, remove the normal index on the name field first, and then create the composite primary key for the stu_id and name fields:
Summary: Two ways to create a primary key at the beginning of the article, the second method can not be used when creating a composite primary key, the composite primary key to be created at the same time, delete.
Solution to multiple primary key defined error message in MySQL