relational schema and concept of keys | Relational Model and Relational Algebra | 2114112 Database Management System
Relation Schema & Keys
The structural blueprint of a database — how tables are defined, how rows are uniquely identified, and how tables link together.
What is a Relation Schema?
A relation schema defines the logical blueprint of a single table in a database. It specifies the relation's name and the list of attributes (columns) it contains — along with the domain (permitted data type) for each attribute. It is the time-invariant template describing data, distinct from the actual data rows (the relation instance) which change over time.
Relation Name (R)
The unique identifier for the table, e.g., EMPLOYEE, DEPARTMENT.
Attributes (A₁…Aₙ)
The named columns of the relation. Each attribute plays a role within a specific domain (data type).
Degree / Arity
The total number of attributes n in the schema. A relation with 5 columns has degree 5.
Domain (D)
The predefined set of permitted atomic values for an attribute, e.g., INTEGER, VARCHAR(50), DATE.
Relation Instance
The actual data rows at a point in time. Instances change; the schema stays constant.
Database Schema
A collection of relation schemas plus integrity constraints forms a complete relational database schema.
The Concept of Keys
Because a relation is mathematically a set of tuples, no two tuples can be identical. Keys formalise and enforce this uniqueness. They act as unique identifiers for rows and establish how different tables link together — forming the backbone of relational integrity.
🔑 Key Hierarchy
Any set of attributes that uniquely identify a tuple
Minimal superkey — no redundant attributes
The chosen candidate key
Remaining candidate keys
| Key Type | Minimal? | NULL Allowed? | One per Relation? | Purpose |
|---|---|---|---|---|
| Superkey | ✗ | — | ✗ (many) | Broad uniqueness guarantee; may have redundant attributes. |
| Candidate Key | ✓ | — | ✗ (many) | Minimal unique identifier; all PKs come from this pool. |
| Primary Key | ✓ | ✗ Never | ✓ Exactly one | Principal row identifier; enforces entity integrity. |
| Secondary Key | ✓ | Context | ✗ (many) | Unused candidate keys; still enforce uniqueness. |
| Foreign Key | ✗ | ✓ | ✗ (many) | Links tables; enforces referential integrity. |
Key Types — In Depth
🔷 Superkey Broad
- Definition: Any set of one or more attributes whose combined values uniquely identify every tuple in a relation.
- Uniqueness constraint: No two distinct tuples can ever share the same value for a superkey's attributes.
- Default superkey: Every relation has at least one — the set of all its attributes combined.
- Limitation: A superkey may contain extraneous (redundant) attributes that aren't necessary for uniqueness.
🔑 Candidate Key Minimal Superkey
- Definition: A superkey with no redundant attributes — the smallest possible set that still guarantees uniqueness.
- Minimality property: Removing any single attribute from a candidate key must break its ability to uniquely identify tuples.
- Multiple candidates: A relation schema may have several distinct candidate keys.
- Pool for PK: The primary key is always chosen from the set of candidate keys.
🔴 Primary Key Principal Identifier
- Definition: The one candidate key chosen by the database designer to be the principal row identifier.
- Notation: Primary key attributes are underlined in schema diagrams.
- Stability recommendation: Choose a primary key whose values are never (or very rarely) changed over time.
⬜ Secondary Keys Unique Keys
- Definition: Any candidate key that was not selected as the primary key.
- Behaviour: Still enforce uniqueness across the relation — equivalent to a UNIQUE constraint in SQL.
- Alternate name: Often called alternate keys or unique keys.
🟢 Foreign Key Referential Link
- Definition: A set of attributes in one relation (the referencing relation) whose values must match the primary key values in another relation (the referenced relation).
- NULL allowed: A foreign key can be NULL — meaning the tuple does not currently reference any row in the referenced relation.
- Direction matters: FK values must exist in the referenced PK, but not every PK value needs to be referenced.
Comments
Post a Comment