Reputation: 1873
primary key
constraint on a mysql
database table column automatically mean there is an index created on given column?
key
constraint on the column already being the primary key
?Upvotes: 4
Views: 2959
Reputation: 7590
In MySQL a PRIMARY or UNIQUE KEY creates an index on the columns defined in the constraint. If there are multiple columns a composite index is created.
If its an InnoDB table the PRIMARY KEY also becomes the clustered index for the table.
It doesn't make sense to add additional indexes with the same definitions as a PRIMARY/UNIQUE.
For other RDBMS an index will be required for these constraints. Even if you are allowed to create a constraint without an appropriate index, it will be required to get any reasonable performance.
Upvotes: 4
Reputation: 28676
primary key
is an index in MySQL too.The primary key for a table represents the column or set of columns that you use in your most vital queries. It has an associated index, for fast query performance.
https://dev.mysql.com/doc/refman/5.5/en/optimizing-primary-keys.html
For the differences between primary key and unique index, you can see: difference between primary key and unique key
Upvotes: 1