380 likes | 1.48k Views
Database Lecture Notes Normalization 1 – Functional Dependencies. Dr. Meg Murray mcmurray@kennesaw.edu. How Many Tables?. Should we store these two tables as they are, or should we combine them into one table in our new database?. Important Relational Model Terms. Entity Relation
E N D
DatabaseLecture NotesNormalization 1 – Functional Dependencies Dr. Meg Murray mcmurray@kennesaw.edu
How Many Tables? Should we store these two tables as they are, or should we combine them into one table in our new database?
Important Relational Model Terms Entity Relation Functional Dependency Determinant Candidate Key Composite Key Primary Key Surrogate Key Foreign Key Referential integrity constraint Normal Form Multivalued Dependency
Relation Relational DBMS products store data about entities in relations, which are a special type of table A relation is a two-dimensional table that has the following characteristics: Rows contain data about an entity Columns contain data about attributes of the entity All entries in a column are of the same kind Each column has a unique name Cells of the table hold a single value The order of the columns is unimportant The order of the rows is unimportant No two rows may be identical KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) © 2008 Pearson Prentice Hall
A Relation • A relation is a two-dimensional table that has the following characteristics: • Rows contain data about an entity • Columns contain data about attributes of the entity • All entries in a column are of the same kind • Each column has a unique name • Cells of the table hold a single value • The order of the columns is unimportant • The order of the rows is unimportant • No two rows may be identical KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) © 2008 Pearson Prentice Hall
Is this a Relation? • A relation is a two-dimensional table that has the following characteristics: • Rows contain data about an entity • Columns contain data about attributes of the entity • All entries in a column are of the same kind • Each column has a unique name • Cells of the table hold a single value • The order of the columns is unimportant • The order of the rows is unimportant • No two rows may be identical
Is this a Relation? • A relation is a two-dimensional table that has the following characteristics: • Rows contain data about an entity • Columns contain data about attributes of the entity • All entries in a column are of the same kind • Each column has a unique name • Cells of the table hold a single value • The order of the columns is unimportant • The order of the rows is unimportant • No two rows may be identical
Functional Dependency A functional dependency occurs when the value of one (a set of) attribute(s) determines the value of a second (set of) attribute(s) in the same table: StudentID StudentName StudentID (DormName, DormRoom, Fee) KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) © 2008 Pearson Prentice Hall
(CookiePrice, Qty) BoxPrice Functional Dependency • Functional dependencies may be based on equations: ExtendedPrice = Quantity X UnitPrice (Quantity, UnitPrice) ExtendedPrice • Illustration… • The price of one cookie can determine the price of a box of 12 cookies • But functional dependencies are not equations! KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) © 2008 Pearson Prentice Hall
Determinant (CookiePrice, Qty) BoxPrice Determinants • The attribute (or attributes) that we use as the starting point (the variable on the left side of the equation) is called a determinant KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) © 2008 Pearson Prentice Hall
Functional Dependencies ObjectColor Weight ObjectColor Shape ObjectColor (Weight, Shape) KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) © 2008 Pearson Prentice Hall
Functional Dependencies Weight ObjectColor [FD? Yes or No] Shape ObjectColor [FD? Yes or No] (Weight, Shape) ObjectColor [FD? Yes or No] KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) © 2008 Pearson Prentice Hall
Composite Determinants Composite determinant: A determinant of a functional dependency that consists of more than one attribute (StudentName, ClassName) (Grade) KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) © 2008 Pearson Prentice Hall
Candidate/Primary Keys and Functional Dependency • By definition…A candidate key of a relation will functionally determine all other attributes in the row • Likewise, by definition…A primary key of a relation will functionally determine all other attributes in the row KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) © 2008 Pearson Prentice Hall
(EmpLastName, EmpPhone) (EmployeeID) Primary Key and Functional Dependency Example **Remember the Primary Key determines all other attributes KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) © 2008 Pearson Prentice Hall
Functional Dependencies • Another way to think about it: • Functional Dependencies = a single-valued fact • Is Y a fact related to X? • Is SKU_Description related to SKU • Or Does X determine Y? • Does SKU determine SKU_Description KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) © 2008 Pearson Prentice Hall
Functional Dependencies in the SKU_DATA Table • Y is "functionally dependent" on X if it is invalid to have two records with the same X-value but different Y-values. • An X-value must always occur with the same Y-value. KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) © 2008 Pearson Prentice Hall
Functional Dependencies in the SKU_DATA Table SKU (SKU_Description, Department, Buyer) SKU_Description (SKU, Department, Buyer) Buyer Department KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) © 2008 Pearson Prentice Hall
Functional Dependencies in the ORDER_ITEM Table KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) © 2008 Pearson Prentice Hall
Functional Dependencies in the ORDER_ITEM Table (OrderNumber, SKU) (Quantity, Price, ExtendedPrice) (Quantity, Price) (ExtendedPrice) KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) © 2008 Pearson Prentice Hall
How to Discover Determinants Often business rules We have been discovering determinants from a table of attributes Often the Functional Dependencies are assessed before a Table is constructed
More on FDs and Keys A candidate key is a key that determines all of the other columns in a relation It may be a determinant key However NOT all determinant keys are candidate keys SKU (SKU_Description, Department, Buyer) SKU_Description (SKU, Department, Buyer) Buyer Department Which are candidate keys? Which is a determinate key but not a candidate key? KROENKE and AUER - DATABASE CONCEPTS (3rd Edition) © 2008 Pearson Prentice Hall
So… • When X is a key, then all fields are by definition functionally dependent on X in a trivial way, since there can't be two records having the same X value. 3-24
One last word on FD In this table, there is not a unique identifier so there is no functional dependency Although each person has a unique address, a given name can appear with several different addresses • Functional dependencies only exist when the things involved have unique and singular identifiers ---------------------------------------------- --- | PERSON | ADDRESS | ----------------+---------------------- | John Smith | 123 Main St., New York | | John Smith | 321 Center St., San Francisco | ------------------------------------------------------------ 3-25
In- class http://adbc.kennesaw.edu Database Design Functional Dependency