Описание тега key
Keys In General
A "key" is unique identifier used to retrieve a paired value. In an associative data structure such as hashtable/hashmap or balanced tree, as in a database, each value is paired with a key; an arbitrary value can be retrieved given its key.
In opposition to an array index, a key doesn't necessarily determine the physical position of the value in the data structure.
Keys in Relational Databases
Definition
- A "superkey" is any set of attributes that, when taken together, uniquely identify rows in the table.
- A minimal1 superkey is called "candidate key", or just "key".
1 That is, a superkey that would stop being unique (and therefore, being a superkey) if any of the attributes were removed from it.
Kinds of Keys
All keys are logically equivalent, but one of them is chosen as "primary", for historical reasons and convenience. The remaining keys are called "alternate".
In addition to that, "natural" keys can be distinguished from "surrogate" keys, based on their "meaning".
Keys and Indexes
A Key is a different concept from an index. A Key is a logical concept that changes the meaning of data, which the index doesn't. An index merely changes the time needed to manipulate the data, shortening it significantly if used properly.
An index can exist on non-key columns. Conversely, a key can exist on non-indexed columns, although this is usually forbidden in practice, for performance reasons.
Keys and Foreign Keys
A foreign key references a key. The foreign key itself doesn't have to be a key.
Keys and Tables
In relational databases, a "table" is a physical representation of the mathematical concept of a "relation", which is a set. A set either contains an element or it doesn't. It cannot contain the same element multiple times. If there isn't at least one key in the table, then the same row can exist multiple times in the table, so the table no longer represents a set and therefore no longer represents a relation.
In other words, a database without keys is not relational database.