There are two ways to create a primary key: create table table name( Field name type, Field name type, … primary key(name) ); or create table table name( Field name type primary key, Field name type, … ); But please note that if you want to create a composite primary key, you cannot use the second method. Here the error "Multiple primary key defined" is reported, indicating that multiple primary keys are defined. The correct way to write it is as follows: If a composite primary key is set for an item, the composite primary key is created and deleted at the same time, so the primary key needs to be deleted. However, auto-increment is set here, so the auto-increment needs to be deleted first before the primary key can be deleted. If the auto-increment is not deleted first and the primary key is deleted directly, an error will be reported (as shown below). You need to delete the auto-increment first: If we create a composite primary key here, we first delete the normal index on the name field, and then create a composite primary key for both the stu_id and name fields: Summary: Of the two ways to create primary keys written at the beginning of the article, the second method cannot be used when creating a composite primary key; composite primary keys must be created and deleted at the same time. The above is the solution to the Multiple primary key defined error message in MySQL. Thank you for reading and supporting 123WORDPRESS.COM. You may also be interested in:
|
<<: An in-depth introduction to React refs
>>: Solution to Linux not supporting all commands
illustrate: VMware IOInsight is a tool that helps...
Table of contents 1. Download 2. Installation 3. ...
Nginx logs can be used to analyze user address lo...
virtualenv is a tool for creating isolated Python...
Uninstall the old version of MySQL (skip this ste...
Today's article mainly introduces the reload ...
Table of contents 1. Data Manipulation Language (...
When making a website, I found that video files, s...
Simply put, delayed replication is to set a fixed...
IP masquerading and port forwarding Firewalld sup...
This article shares the specific code for JavaScr...
Preface Recently, during an interview, I was aske...
In order to prevent non-compliant data from enter...
How to uninstall MySQL database under Linux? The ...
This article shares the specific code of JavaScri...