Relational databases use the terms index and key to indicate similar concepts.
An index is like an index in a book, used to find specific topics, on specific pages, in a book, very quickly (without having to read the entire book).
Similarly, an index in a relational database
is a copy of a part of a table, perhaps structured in a specific format such as a BTree index.
An index can be created on any field in a table. A key, on the other hand, is more of a concept than a physical thing because a key is also an index.
In a relational database, a key is a term used to describe the fields in tables linking tables together to form relationships (such as a one-to-many relationship between two tables). A key is both a key and an index. A key is an index because it copies fields in a table into a more efficient searching structure. A key is also a key, its namesake, because it creates a special tag for a field, allowing that field to be used as a table relationship field, linking tables together into relations.
There are three types of keys:
- primary key,
- unique key, and
- foreign key.