Chapter 2. The Relational Model (cont.)

Slides:



Advertisements
Similar presentations
Normalization Process: Exercise 2: Step 1 IST2101 Step 1. Identify all the candidate keys of the relation. (Attorney, ClientNumber, MeetingDate)
Advertisements

1 Class Agenda (04/03 and 04/08)  Review and discuss HW #8 answers  Present normalization process Enhance conceptual knowledge of database design. Improve.
Lab Exercise This Week PHP Basics See last Friday’s slides for requirements Make sure you show the final results to TA to get credit 1IST210.
The Relational Model Chapter Two DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 7 th Edition.
The Relational Model Chapter Two DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 6 th Edition.
The Relational Model Chapter Two. 2 Chapter Objectives Learn the conceptual foundation of the relational model Learn the conceptual foundation of the.
The Relational Model Chapter Two Functional Dependency.
The Database Approach u Emphasizes the integration of data across the organization.
Database Design Conceptual –identify important entities and relationships –determine attribute domains and candidate keys –draw the E-R diagram Logical.
Structured Query Language Part II Chapter Three CIS 218.
The Relational Model CIS 218. Entity A Person, Place, Thing or Transaction Something the user wants to track.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall 3-1 David M. Kroenke Database Processing Chapter 3 Normalization.
The Relational Model Chapter Two (Excerpts) DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
The Relational Model Chapter Two DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 5 th Edition.
Chapter 2. The Relational Model (cont.) IST2101. Review: Functional Dependency A relationship between attributes: some attribute(s) determine the value.
N. J. Taylor Database Management Systems (DBMS) 1.
Chapter 3 The Relational Model and Normalization
CHAPTER 7 Database: SQL, MySQL. Topics  Introduction  Relational Database Model  Relational Database Overview: Books.mdb Database  SQL (Structured.
Database Management System Lecture 6 The Relational Database Model – Keys, Integrity Rules.
DAY 15: ACCESS CHAPTER 2 Larry Reaves October 7,
1 Class Agenda (11/07 and 11/12)  Review HW #8 answers  Present normalization process Enhance conceptual knowledge of database design. Improve practical.
DATABASE DESIGN I IST 210: Organization of Data IST210 1.
Database Design II (Case Studies: Step 2) IST 210: Organization of Data IST2101.
The Relational Data Model and Relational Database Constraints
R ELATIONAL D ATA M ODEL Joe Meehean 1. R ELATIONAL D ATA M ODEL Data stored as a set of relations really just tables Tables related to one another through.
Database Basics CPSC 4670/ Purpose of a Database The purpose of a database is to keep track of things Unlike a list or spreadsheet, a database.
The Relational Model and Normalization R. Nakatsu.
SALINI SUDESH. Primarily a tool to validate and improve a logical design so that it satisfies certain constraints that avoid unnecessary duplication of.
Schema Refinement and Normal Forms 20131CS3754 Class Notes #7, John Shieh.
DAVID M. KROENKE’S DATABASE PROCESSING, 10th Edition © 2006 Pearson Prentice Hall, Modified by Dr. Mathis 3-1 David M. Kroenke’s Chapter Three: The Relational.
IST 210: ORGANIZATION OF DATA Chapter 1. Getting Started IST210 1.
MS Access: Creating Relational Databases Instructor: Vicki Weidler Assistant: Joaquin Obieta.
The Relational Model Chapter Two DAVID M. KROENKE’S DATABASE CONCEPTS, 2 nd Edition.
The Relational Model Chapter Two DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 3 rd Edition.
Normalization Process: Exercise 1: Step 1 IST2101 Step 1. Identify all the candidate keys of the relation. StudentNumber.
Chapter 2. The Relational Model IST2101. Chapter 1 Review Potential problems with Lists – Deletion – Update – Insertion Avoid these problems using a relational.
Relational Database. Database Management System (DBMS)
Copyright 2007, Paradigm Publishing Inc. ACCESS 2007 Chapter 2 BACKNEXTEND 2-1 LINKS TO OBJECTIVES Creating Related Tables Creating Related Tables Determining.
The Relational Model J.G. Zheng Jan 2010 CIS 8040 Database Management Systems.
INFORMATION TECHNOLOGY DATABASE MANAGEMENT. Adding a new field 1Right click the table name and select design view 2Type the field information at the end.
THE RELATIONAL MODEL II IST 210: Organization of Data IST210 1.
INCLUDING CONSTRAINTS lecture5. Outlines  What are Constraints ?  Constraint Guidelines  Defining Constraint  NOT NULL constraint  Unique constraint.
Chapter 2: Intro to Relational Model. 2.2 Example of a Relation attributes (or columns) tuples (or rows)
Chapter 2. The Relational Model (cont.) IST2101. Review: Determinant vs. Candidate Key IST2102 DeterminantsCandidate Key (StudentID, CourseID) StudentID.
+ Relational Model IST210 Class Lecture. + Premiere Products A new company that is going to sells random merchandise via sales representatives You have.
CTFS Workshop Shameema Esufali Asian data coordinator and technical resource for the network
Assignment 1 Uploaded to course website Due next Tuesday, Sep 1, at 11:59pm.
Database Design I (In-Class Exercise Answer) IST 210: Organization of Data IST2101.
THE RELATIONAL MODEL I IST 210: Organization of Data IST210 1.
© 2002 by Prentice Hall 1 The Relational Model David M. Kroenke Database Concepts 1e Chapter 2 2.
The Relational Model Chapter Two DAVID M. KROENKE and DAVID J. AUER DATABASE CONCEPTS, 4 th Edition.
Including Constraints. What Are Constraints? Constraints enforce rules at the table level. You can use constraints to do the following: – Enforce rules.
Data Modeling and Entity-Relationship Model I
MIDTERM REVIEW IST 210 Organization of Data IST210 1.
Database Design I IST 210: Organization of Data IST2101.
Database Planning Database Design Normalization.
Chapter 1. Getting Started IST 210: Organization of Data IST2101.
DATABASE DESIGN II IST 210: Organization of Data IST210 1.
Database Design I (In-Class Exercise Answer) IST 210: Organization of Data IST2101.
CSIS 115 Database Design and Applications for Business
CSIS 115 Database Design and Applications for Business
The Relational Model and Database Normalization
The Relational Model Chapter Two DATABASE CONCEPTS, 3rd Edition
 2012 Pearson Education, Inc. All rights reserved.
IST 210: Organization of Data
CIS 155 Table Relationship
Database Management Systems (DBMS)
Copyright © 2018, 2015, 20 Pearson Education, Inc. All Rights Reserved Database Concepts Eighth Edition Chapter # 2 The Relational Model.
Including Constraints
Presentation transcript:

Chapter 2. The Relational Model (cont.) IST210

Review of Previous Class: Keys StudentID FirstName LastName DOB 9123450 John Smith Jan. 1, 1989 9123451 Adam Jun. 1, 1988 9123452 Jane Aug, 1,1989 9123453 Josh Cohen Aug. 1,1989 Key: one (or more) columns of a relation that is (are) used to uniquely identify a row. StudentID, (StudentID, FirstName), … Candidate key: a candidate to become the primary key StudentID Primary key: a candidate key chosen to be the main key for the relation (StudentID, FirstName, LastName, DOB) Surrogate key: a column with unique numeric values that is added to a relation to serve as the primary key IST210

Relationships Between Tables A table is related to other tables Shared columns in Chapter 1 Primary Key StudentID is the primary key in STUDENT table StudentID FirstName LastName DOB 9123450 John Smith Jan. 1, 1989 9123451 Adam Jun. 1, 1988 9123452 Jane Aug, 1,1989 9123453 Josh Cohen Aug. 1,1989 ClubID ClubName PresidentStudentID 12 Football 9123450 13 Medical 9123453 15 Dance 9123452 Foreign Key PresidentStudentID is the foreign key in CLUB table Italic CLUB(ClubID, ClubName, PresidentStudentID) STUDENT(StudentID, FirstName, LastName, DOB) IST210

A Foreign Key To preserve relationships of relations, it is needed to create a foreign key A foreign key is a primary key from one table placed into another table The key is called a foreign key in the relation that receives the key Presenting a foreign key Attributes name in italic RELATION_NAME(Column1, Column 2, …, Column n) IST210

Foreign Key Example Foreign Key Primary Key PROJECT MANAGER ProjID ProjName MgrID MgrID MgrName Office Foreign Key Primary Key PROJECT(ProjID, ProjName, MgrID) MANAGER(MgrID, MgrName, Office) IST210

Foreign Key Example Foreign Key Primary Key EMPLOYEE EmpID DeptID EmpName Foreign Key DEPARTMENT DeptID DeptName Location Primary Key DEPARTMENT(DeptID, DeptName, Location) EMPLOYEE(EmpID, DeptID, EmpName) IST210

Foreign Key Example STUDENT(StudentID, Name, Department, Email) STUDENT table COURSE table REGISTRATION table STUDENT(StudentID, Name, Department, Email) COURSE(CourseID, Instructor, CourseName, Location) REGISTRATION(StudentID, CourseID) An attribute can be both part of primary key and foreign key! IST210

Referential Integrity Constraint Student ID CourseID 101 210 102 103 104 220 105 230 250 250 does not exist in COURSE table! Every value of a foreign key must match a value of an existing primary key IST210

Summary of Keys A Key is one (or more) columns of a relation that is (are) used to uniquely identify a row Single key and composite key A key (can be) a candidate key (may be chosen to be) a primary key A surrogate key: an intentionally created attribute to serve as a primary key A foreign key: link to the primary key in another table IST210

Exercise: True/False Suppose we have two tables: BOOK(BookID, Title, PublishedYear, PublisherID) PUBLISHER(PublisherID, Name, Location) Q1. PublisherID is a foreign key in PUBLISHER table? IST210

Exercise: True/False Suppose we have two tables: BOOK(BookID, Title, PublishedYear, PublisherID) PUBLISHER(PublisherID, Name, Location) Q2. Is following design about primary key and foreign key correct? IST210

Exercise: True/False Suppose we have two tables: BOOK(BookID, Title, PublishedYear, PublisherID) PUBLISHER(PublisherID, Name, Location) Q3. Is following design about primary key and foreign key correct? IST210

Exercise: True/False Suppose we have two tables: BOOK(BookID, Title, PublishedYear, PublisherID) PUBLISHER(PublisherID, Name, Location) Q4. Is following design about primary key and foreign key correct? IST210

Question from last class What’s the primary key of this table? EmployeeID EmployeeName Skill Work Location 101 Jones Typing 114 Main Street Shorthand Whittling 102 Bravo Light Cleaning 73 Industrial Way 103 Ellis Alchemy Flying 104 Harrison EmployeeID: supposed to be a surrogate key. but not a primary key of the table?

How to design a well-formed model? Revisit Chapter 1 Break list into tables, one for each theme Tables are joined together using the value of data No redundancy, easy to update, modify, delete Functional Dependency  Formal way to determine if a list/table is well-formed Normalization Process  Formal way to break a list into tables IST210

Functional Dependency A relationship between attributes: some attribute(s) determine the value of some other attribute(s) in the same table These attributes we name them determinant The other attributes are functionally dependent on this determinant CookieCost = NumberOfBoxes * $5 NumberOfBoxes  CookieCost Functionally dependent on NumberofBoxes determinant CookieCost = NumberOfBoxes * UnitPrice (UnitPrice, NumberOfBoxes)  CookieCost The composite forms determinant IST210

Determinant in Relations StudentID FirstName LastName DOB 9123450 John Smith Jan. 1, 1989 9123451 Adam Jun. 1, 1988 9123452 Jane Aug, 1,1989 9123453 Josh Cohen Aug. 1,1989 Determinant: StudentID StudentID  (FirstName, LastName, DOB) ClubID ClubName President 12 Football 9123450 13 Medical 9123453 15 Dance 9123452 Determinant: ClubID ClueID  (ClubName, President) Determinant: CourseID CourseID  (Instructor, CourseName, Location) Determinant = Candidate key? IST210

Review: Candidate Key Old Def: A candidate key is a special key Any subset of a candidate key is NOT a key (StudentID, FirstName) is not a candidate key, because StudentID is a key New Def: A candidate key is “one or more attributes that functionally determine all the other attributes of the relation”. IST210

Determinant = Candidate Key? In a relation, a candidate key must be a determinant Candidate Key Determinants In a relation, a determinant may not be a candidate key StudentID CourseID (StudentID, CourseID) (StudentID, CourseID) A relation is well-formed if and only if every determinant is a candidate key. IST210

Normalization Normalization is a process of breaking a table with more than one theme into a set of tables to ensure that each table is well-formed No data redundancy Data can be inserted, deleted, or modified without creating modification problems IST210

Normalization Principles Relational design principle for normalized relations: To be a well-formed relation, every determinant must be a candidate key Any relation that is not well-formed should be broken into two or more well-formed relations IST210

Normalization Process Identify all the candidate keys of the relation. Identify all the functional dependencies in the relation. Examine the determinants of the functional dependencies. If any determinant is not a candidate key, the relation is not well formed. In this case: Place the columns of the functional dependency in a new relation of their own. Make the determinant of the functional dependency the primary key of the new relation. Leave a copy of the determinant as a foreign key in the original relation. Create a referential integrity constraint between the original relation and the new relation. Repeat step 3 as many times as necessary until every determinant of every relation is a candidate key. IST210

Normalization Process: Example 1: Step 1 Step 1. Identify all the candidate keys of the relation. PrescriptionNumber IST210

Normalization Process: Example 1: Step 2 Step 2. Identify all the functional dependencies in the relation. PrescriptionNumber  (Date, Drug, Dosage, CustomerName, CustomerPhone, CustomerEmail) Drug  Dosage? No CustomerEmail  (CustomerName, CustomerPhone)? Yes This is a trivial dependency by the definition of candidate key IST210

Normalization Process: Example 1: Step 3 Step 3. If any determinant is not a candidate key, the relation is not well formed. Determinant: PrescriptionNumber, CustomerEmail Candidate key: PrescriptionNumber CustomerEmail is NOT a candidate key, so the relation NOT well formed Then, we will normalize it (break it into multiple relations) IST210

Normalization Process: Example 1: Step 3 Step 3. Examine the determinants of the functional dependencies. If any determinant is not a candidate key, the relation is not well formed. In this case: Place the columns of the functional dependency in a new relation of their own. CUSTOMER (CustomerEmail, CustomerName, CustomerPhone) Make the determinant of the functional dependency the primary key of the new relation. Leave a copy of the determinant as a foreign key in the original relation. PRESCRIPTION(PrescriptionNumber, Date, Drug, Dosage, CustomerEmail) Create a referential integrity constraint between the original relation and the new relation. CustomerEmail in PRESCRIPTION must exist in CustomerEmail in CUSTOMER IST210

Normalization Process: Example 1: Step 4 Step 4. Repeat step 3 as many times as necessary until every determinant of every relation is a candidate key. CUSTOMER (CustomerEmail, CustomerName, CustomerPhone) PRESCRIPTION(PrescriptionNumber, Date, Drug, Dosage, CustomerEmail) CustomerEmail in PRESCRIPTION must exist in CustomerEmail in CUSTOMER Well-formed relational model design IST210

Normalization Process: Exercise 1 Step 1. Candidate keys: Step 2. Functional dependencies: Step 3. Determine if the relation is well-formed. If not, split the relation into multiple well-formed relations and specify all the primary keys, foreign keys and referential integrity constraints: Hint: If any determinant is not a candidate key, the relation is not well formed. IST210