ER→ Conceptual
Relational Model → Logical
Entity vs. Attribute: Should equipment be E or A for a Room
- if want to keep track of every piece of Equipment → Ent.
- if it’s a simple description of the type of equipment → Att.
ISA Relationship
Overlap: Disjoint (only one) or Overlapping (possibly many)
Covering: Total (all MUST be a sub) or partial (some aren’t)
Weak Entities - uniquely identified only by primary key of owner
- owner + weak ent. MUST participate in a one(owner)-to-many(W.E.)
Aggregation - treat a relationship set as an entity for participation
Keys FilmedIn: animalID, movieID
Keys Monitors: animalD, movieID
===========================================================================================================================
CREATE TABLE Student
DROP TABLE Student - destroys Student, Schema info+tuples are deleted
ALTER TABLE Student
ADD COLUMN gpa REAL;
- schema Students altered by adding new attribute
- every current tuple is extended with a null value in the new attribute
INSERT (single tuple)
INTO Student (sid, name, …, major)
VALUES (1234, Joe S., …, CPSC)
DELETE (with condition)
FROM Student
WHERE name = “Smith”
Integrity Constraints (ICs) - condition that must be true for ANY instance in
- specified with schema is defined, and are checked with relations are modified
Key Constraints
One or more attributes form a key (or candidate key ) for relation if:
1.
No distinct tuple can have same value for attributes in the key
2.
No subset of S itself is a key (would be a superkey then)
3.
If it’s underlined LMAO
One of the possible keys is chosen to be the primary key and cannot be null
Other candidate keys are specified using the UNIQUE constraint
-
-
UNIQUE must be used for one-to-one and candidate keys
Used for “there is a single _____”
Ex) For a given student and course, there is a single grade:
CREATE TABLE Student
(sid INT, dept CHAR, course# CHAR, mark INT,
PRIMARY KEY (sid, dept, course#)
UNIQUE (dept, course#, mark)
Referential Integrity - All foreign keys reference existing entities
Enforcing Referential Integrity:
- sid in Grade is a foreign key that references Student
- if a Grade tuple w/ a non-existent student ID is inserted, REJECT IT
- if a Student tuple is deleted
- Set sid in Grade tuples that refer to it as null
- BUT problem if sid is a primary key…
- Set sid in Grade tuples that refer to it to a default sid
Translating ISA Hierarchy database
=========================================================
I
I
Trivial FD: AB → A
Translating ISA Hierarchy
I If a relation only has 2 attributes → automatically 3NF and BCNF
I
=====================================
Deriving FDs - Armstrong Axioms:
Reflexivity : If Y ⊆ X, then X → Y
Augmentation : If X → Y, then XZ → YZ for any Z
Transitivity : If X → Y and Y → Z then X → Z
Union : If X → Y and X → Z then X → YZ
Decomposition : If X → YZ, then X → Y and X → Z
Closure of set of attributes X is X+
Decomposition into BCNF
1.
Pick any f in FD st. f violates BCNF in form X → b
2.
Decompose R into 2 relations: R(A-B) & R(X ∪ B) a.
Recurse on R1 and R2 using FD
Find minimal keys by writing out closures of all FDs
Decomposition into 3NF: Lossless Join
1.
Compute Minimal Cover of F, F’
2.
Decompose using F’ if violating 3NF
Decomposition into 3NF: Min. Cover and Synthesis
1.
Find minimal cover F’
2.
For every FD X → b in F’, add relation Xb to decomp. for R
3.
If there are no relations in the decomposition that contain all attributes of a key, add in a relation that contains all attributes of the key → Preserve lossless join
Ex)
BCNF vs. 3NF:
- BCNF guarantees removal of all anomalies
- 3NF has some anomalies but preserves all dependencies
- If relation is in BCNF, it is in 3NF
- If relation is in 3NF, it might not be in BCNF if all following are true:
1.
R has multiple keys
2.
Keys are composite (not single attributed/Standard form)
3.
The keys overlap