Understanding Keys and Indexes

The terms keys and indexes are often used interchangeably. A key column stores values that are used to filter rows in the table, either in the WHERE clause when querying that table or as part of a join to indicate the relationship between two tables.

A key column in MySQL is always indexed, but you can create an index on any table column or on multiple columns.

Primary Keys

Each table can contain only one primary key, which is a unique identifier for each row in the table. Often the primary key is an AUTO_INCREMENT column so that a new unique number is assigned automatically for each row added to the table.

You can be sure that when you query a table using a filter on a primary key field, MySQL will return only ...

Get Sams Teach Yourself MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.