Composite key: Key composed of multiple attributes.
Key attribute: Attribute that is part of a key.
Key Types
Superkey: Attribute(s) that uniquely identifies a row.
Example: STUNUM or (STUNUM, STU_LNAME)
Candidate Key: Superkey without unnecessary attributes.
Example: STU_NUM
Primary Key: Candidate key to uniquely identify all other attribute values; cannot contain null entries.
Example: STU_NUM
Foreign Key: Attribute(s) in one table that must match the primary key in another table or be null.
Example: STU_SECT
Secondary Key: Attribute(s) used for data retrieval.
Example: (STULNAME, STUFNAME, STU_MI)
Integrity Rules
Entity integrity: Each row has a unique identity.
Referential integrity: Every reference to an entity instance is valid.
Entity Integrity
Requirement: Primary key entries are unique and not null.
Purpose: Unique row identity; foreign keys can reference primary keys.
Example: Invoice numbers must be unique and not null.
Referential Integrity
Requirement: Foreign key may be null (if not part of primary key) or match a primary key value in another table; every non-null foreign key must reference an existing primary key.
Purpose: Prevents invalid entries; ensures valid relationships between tables.
Example: A customer might not have an assigned sales representative, but it will be impossible to have an invalid sales representative.
Flags
Special codes used to avoid nulls by indicating the absence of some value.
Example: NS for an unassigned section; requires a dummy row in the SECTIONS table.
Relational Algebra
Mathematical principles for manipulating relational table contents.
Closure: Using relational algebra operators on tables produces new tables.
Predicate: Condition to be evaluated.
Relational Operators
SELECT (σ): Retrieves a subset of rows.
Syntax: σCONDITION(TABLE)
Example: σSTUNUM=324452(STUDENTS)
PROJECT (π): Retrieves a subset of columns.
Syntax: πCOLUMNS(TABLE)
Example: πSTU<em>FNAME,STU</em>LNAME(STUDENTS)
UNION (⋃): Merges two union-compatible tables, dropping duplicates.
Union-compatible: Tables with the same number of columns and compatible domains.
Syntax: TABLE1⋃TABLE2
Example: STUDENTS⋃SECTIONS
INTERSECT (⋂): Retrieves rows common to two union-compatible tables.
Syntax: TABLE1⋂TABLE2
Example: STUDENTS⋂SECTIONS
DIFFERENCE (–): Retrieves rows from one table not found in another union-compatible table.
Syntax: TABLE1–TABLE2
Example: STUDENTS–SECTIONS
PRODUCT (x): Retrieves all possible pairs of rows from two tables (Cartesian Product).
Syntax: TABLE1xTABLE2
Example: STUDENTSxSECTIONS
JOIN (⋈): Retrieves rows from two tables based on criteria (e.g., common values).