When should I use a primary key or an index?
What are their differences and which is the best?
Basically, a primary key is (at the implementation level) a special kind of index. Specifically:
UNIQUE
- you cannot have more than one row with the same primary key, since its purpose is to uniquely identify rows.NULL
, so the row(s) it consists of must be NOT NULLA table can have multiple indexes, and indexes are not necessarily UNIQUE
. Indexes exist for two reasons: