Skip to main content
All tracks
DBMS

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
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;.

Finished reading?

Mark it complete to track your progress across the docs.

Next: SQL Basics

Questions and discussion

Stuck on something here, or found a clearer way to explain it? Start a thread.

All discussions
  • Ask a question or share what helped
  • React to useful answers
  • Sign in with GitHub to post

Comments are stored in GitHub Discussions and shown here by giscus. PrepVerse never sees your GitHub password.