mysql: the difference between primary key, foreign key and index
Difference between primary key, foreign key and index
definition:
Primary key – uniquely identifies a record, cannot have duplicates, and is not allowed to be empty
Foreign key – the foreign key of a table is the primary key of another table, the foreign key can have duplicates and can be null
index – the field has no duplicate values, but can have a null value
effect:
Primary key – used to ensure data integrity
Foreign keys – used to connect with other tables
Indexes – are to increase the speed of query sorting
Number:
Primary Key – There can only be one primary key
Foreign keys – a table can have multiple foreign keys
Indexes – a table can have multiple unique indexes