Skip to main content

Relational Model and Keys

Data is stored in relations (tables) made of tuples (rows) and attributes (columns).

Terms​

TermTable equivalent
RelationTable
TupleRow
AttributeColumn
DomainAllowed values of a column
DegreeNumber of columns
CardinalityNumber of rows

Keys​

KeyDefinition
Super keyAny set of attributes that uniquely identifies a row
Candidate keyA minimal super key
Primary keyThe candidate key chosen to identify rows; not NULL
Alternate keyCandidate keys not chosen as primary
Foreign keyAttribute(s) referencing a primary key of another table
Composite keyA key made of more than one attribute
keys.sql
CREATE TABLE department (
dept_id INT PRIMARY KEY,
name VARCHAR(50) UNIQUE NOT NULL
);

CREATE TABLE employee (
emp_id INT PRIMARY KEY,
email VARCHAR(100) UNIQUE,
dept_id INT,
FOREIGN KEY (dept_id) REFERENCES department(dept_id)
);

Integrity constraints​

  • Domain: type and CHECK constraints.
  • Entity: the primary key is unique and not NULL.
  • Referential: a foreign key must match an existing primary key (or be NULL).

Relational algebra (core operators)​

OperatorSymbolMeaning
SelectionσFilter rows
ProjectionπChoose columns
Union / Difference∪ / −Set operations
Cartesian product×All pairs
Join⋈Combine related rows
RenameρRename a relation or attribute

π name (σ salary > 50000 (employee)) is SELECT name FROM employee WHERE salary > 50000;.