Table Key (Cont.)


Definition (Table Key)
Give a table T, with Head(T)=A1…An. A key for the table T, sometimes called a candidate key, is a set of attributes, K=Ai1…Aik, with two properties
  1. (Superkey) If u and v are distinct tuples of T, then by designer intention u[K]v[K]; that is, there will always exist at least one column, Aim, in the set of columns K such that u[Aim]v[Aim].

  2. (Key) No proper subset H of K has the Property 1.
Example (Table Key)
Calculate the keys of T from a given content:

Note that this example is to explain the concept of a key, instead of trying to find the keys from a table content.
T
A B C D
a1 b1 c1 d1
a1 b2 c2 d1
a2 b2 c1 d1
a2 b1 c2 d1
|key| = 1
No single attribute can be a key, since in each column we have at least two equal entries.

D ∈ key
(Superkey) No set S of attributes can be a key if it includes D, since D gives no help in distinguishing rows of T.

|key| = 2
(Key) All rows of T are distinguished by each of AB, AC, and BC.

|key| = 3
(Superkey) Must contain AB, AC, or BC.
Primary Key of a Table
A primary key of a table T is the candidate key chosen by the database designer to uniquely identify specific rows of T.