Home >Database >Mysql Tutorial >MySQL multi-field primary key
MySql multi-field primary key can also become a composite primary key. The composite primary key is also a type of primary key and has the same function and definition as the primary key. The so-called composite primary key means that the primary key of the table contains more than one field.
MySQL multi-field primary key can also become a composite primary key. A composite primary key is also a type of primary key and has the same function and definition as the primary key.
Recommended courses: MySQL Tutorial.
What is the composite primary key of a data table?
The so-called composite primary key means that the primary key of your table contains more than one field.
For example:
create table test ( name varchar(19), id number, value varchar(10), primary key (name,id) )
The combination of the name and id fields above is the composite primary key of your test table
It appears because your name field may have the same name, so you need to Add the ID field to ensure the uniqueness of your record
Generally, the field length and number of fields of the primary key should be as small as possible
When to use a composite primary key?
Use a composite primary key only when a primary key cannot uniquely identify the records in this table
For example, in this case
Commodity brand |
Product model |
The above is the detailed content of MySQL multi-field primary key. For more information, please follow other related articles on the PHP Chinese website!