Okay, here are digital short notes from the provided PDF, formatted for easy readability and with variables and mathematical equations rendered using MathJax:
Relational Databases
Integrity Constraints
- Relation: A named, two-dimensional table of data.
- Unique name, named columns (attributes), unique rows (records).
- Order of columns and rows is irrelevant.
- Attribute values are atomic.
- Relational Structure: Expressed by a tuple:
RelationName(Attribute1, Attribute2, ...)- Example:
EMPLOYEE1(Emp_ID, Name, Dept, Salary)
- Example:
- Relational Keys:
- Primary Key: Uniquely identifies each row.
- Example:
EMPLOYEE1(Emp_ID, Name, Dept, Salary)(Emp_ID is underlined)
- Example:
- Composite Key: Primary key with multiple attributes.
- Example:
DEPENDENT(EmpID, Dependent_Name)
- Example:
- Foreign Key: Represents a relationship between two tables. An attribute in one relation that is the primary key of another relation.
- Example:
EMPLOYEE1(Emp_ID, Name, Dept_Name,Salary),DEPARTMENT(Dept_Name, Location, Fax)(Dept_Name in EMPLOYEE1 is a foreign key)
- Example:
- Primary Key: Uniquely identifies each row.
Integrity Constraints Types
- Domain Constraints: Define allowable values for an attribute.
- Components: domain name, meaning, data type, size, allowable values/range.
- Entity Integrity: Every relation has a primary key; no primary key attribute can be null.
- Referential Integrity: Foreign key value must match a primary key value in the related table (or be null).
- Restrict: Don’t allow delete of “parent” if related rows exist in “dependent”.
- Cascade: Delete “dependent” rows corresponding with the “parent” row to be deleted
- Set-to-Null: Set foreign key in dependent to null if deleting from parent.
Relational Database Design
Pitfalls
- Bad Design Leads To:
- Repetition of Information.
- Inability to represent certain information.
- Design Goals:
- Avoid redundant data.
- Represent relationships among attributes.
- Facilitate checking of integrity constraints.
Example of Bad Design
Lending-schema = (branch-name, branch-city, assets, customer-name, loan-number, amount)- Redundancy:
branch-name,branch-city,assetsrepeated. - Null Values: Cannot store branch information without loans.
Decomposition
-
Break down
Lending-schemainto:Branch-schema = (branch-name, branch-city, assets)Loan-info-schema = (customer-name, loan-number, branch-name, amount)
-
Rule: All attributes of original schema (R) must appear in the decomposition (R1, R2):
-
Lossless-join decomposition: For all possible relations r on schema R
Functional Dependencies (FDs)
-
Constraints on legal relations.
-
Value for a set of attributes uniquely determines the value for another set.
-
Generalization of the notion of a key.
-
Notation: ( functionally determines )
-
Formal Definition: Let R be a relation schema, and . The functional dependency holds on R if and only if for any legal relations r(R), whenever any two tuples and of r agree on the attributes , they also agree on the attributes . That is,
-
Example: In
r(A, B),B → Aholds, butA → Bdoes not.
| A | B |
|---|---|
| 1 | 4 |
| 1 | 5 |
| 3 | 7 |
- Superkey: K is a superkey for relation schema R if and only if
- Candidate Key: K is a candidate key for R if and only if , and for no
- Trivial FD: Satisfied by all instances of a relation (e.g., if ).
Closure of a Set of FDs ()
- Set of all FDs logically implied by F.
- Armstrong’s Axioms:
- Reflexivity: If , then
- Augmentation: If , then
- Transitivity: If and , then
Closure of Attribute Sets ()
- Set of attributes functionally determined by under F.
- Algorithm to compute :
result := α; while (changes to result) do for each β → γ in F do begin if β ⊆ result then result := result ∪ γ end
Canonical Cover
- A “minimal” set of FDs equivalent to F, with no redundancies.
Design Goals Summary
- BCNF (Boyce-Codd Normal Form)
- Lossless join
- Dependency preservation
- SQL does not provide a direct way of specifying functional dependencies other than superkeys.
Multivalued Dependencies (MVDs)
-
Notation:
-
Definition: Let R be a relation schema and let and . The multivalued dependency holds on R if in any legal relation r(R), for all pairs for tuples and in r such that , there exist tuples and in r such that:
-
Simplified Definition: Let be nonempty subsets of attributes in R. (Y multidetermines Z) if and only if for all possible relations r(R), if and , then and
-
Example:
classes(course, teacher, book)course →→ teachercourse →→ book
-
Use of MVDs:
- To test relations to determine whether they are legal under a given set of functional and multivalued dependencies.
- To specify constraints on the set of legal relations.
Fourth Normal Form (4NF)
- A relation schema R is in 4NF with respect to a set D of functional and multivalued dependencies if for all multivalued dependencies in of the form , where and , at least one of the following hold:
- is trivial (i.e., or )
- is a superkey for schema R
- If a relation is in 4NF, it is in BCNF.