Announcements Midterm is Nov. 22 (8:15am – 9:45am) Covers until the end of Normalization You answer in the same exam paper Closed-Book, One sheet is allowed.

Slides:



Advertisements
Similar presentations
Convert ER to Relational Database Entity relation Entity relation Attributes attributes Attributes attributes Primary key primary key Primary key primary.
Advertisements

Announcements Read 6.1 – 6.3 for Wednesday Project Step 3, due now Homework 5, due Friday 10/22 Project Step 4, due Monday Research paper –List of sources.
CS 440 Database Management Systems Practice problems for normalization.
Relational Database. Relational database: a set of relations Relation: made up of 2 parts: − Schema : specifies the name of relations, plus name and type.
Review for Final Exam Lecture Week 14. Problems on Functional Dependencies and Normal Forms.
1 © Prentice Hall, 2002 Chapter 5: Logical Database Design and the Relational Model Modern Database Management 6 th Edition Jeffrey A. Hoffer, Mary B.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Reduction of an E-R Schema to Tables A database which conforms to an E-R diagram can be represented.
©Silberschatz, Korth and Sudarshan7.1Database System Concepts Chapter 7: Relational Database Design First Normal Form Pitfalls in Relational Database Design.
(C) 2000, The University of Michigan 1 Database Application Design Handout #3 January 21, 2000.
CS 405G: Introduction to Database Systems 16. Functional Dependency.
Database System Concepts, 5th Ed. Chapter 6: Entity-Relationship Model.
Chapter 3: Relational Model I Structure of Relational Databases Structure of Relational Databases Convert a ER Design to a Relational Database Convert.
DBSQL 3-1 Copyright © Genetic Computer School 2009 Chapter 3 Relational Database Model.
CMPE 226 Database Systems September 16 Class Meeting Department of Computer Engineering San Jose State University Fall 2015 Instructor: Ron Mak
Concepts of Relational Databases. Fundamental Concepts Relational data model – A data model representing data in the form of tables Relations – A 2-dimensional.
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.
SCUJ. Holliday - coen 1784–1 Schedule Today: u Normal Forms. u Section 3.6. Next u Relational Algebra. Read chapter 5 to page 199 After that u SQL Queries.
Chapter 3: Relational Model  Structure of Relational Databases  Normal forms (chap. 7)  Reduction of an E-R Schema to Relational (Sect. 2.9)  Relational.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Chapter 7 Database Design and The E–R Model. 2 Goals n Facilitate DB design and represent the overall logical structure of the DB. n Definition Entities.
Functional Dependencies and Normalization 1 Instructor: Mohamed Eltabakh
1 Session 2 Welcome: The seventh learning sequence “ Reduction of an EER schema to tables“ Recap : In the previous learning sequence, we discussed the.
Revision Instructor: Mohamed Eltabakh 1.
Logical Database Design (1 of 3) John Ortiz Lecture 6Logical Database Design (1)2 Introduction  The logical design is a process of refining DB schema.
11/07/2003Akbar Mokhtarani (LBNL)1 Normalization of Relational Tables Akbar Mokhtarani LBNL (HENPC group) November 7, 2003.
Revisit FDs & BCNF Normalization 1 Instructor: Mohamed Eltabakh
Final Exam Revision Instructor: Mohamed Eltabakh 1.
Database Management Systems MIT Lesson 02 – Database Design (Entity Relationship Diagram) By S. Sabraz Nawaz.
1 Translating ER Schema to Relational Model Instructor: Mohamed Eltabakh
ICOM 5016 – Introduction to Database Systems Lecture 9 Dr. Manuel Rodriguez Department of Electrical and Computer Engineering University of Puerto Rico,
UNIT_2 1 DATABASE MANAGEMENT SYSTEM[DBMS] [Unit: 2] Prepared By Lavlesh Pandit SPCE MCA, Visnagar.
Database System Concepts, 6 th Ed. ©Silberschatz, Korth and Sudarshan Lecture-03 Introduction –Data Models Lectured by, Jesmin Akhter.
CTFS Workshop Shameema Esufali Asian data coordinator and technical resource for the network
1 The Entity- Relationship Model Instructor: Mohamed Eltabakh Part-2.
Quiz (20 mins) Instructor: Mohamed Eltabakh 1.
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Design Issues Mapping.
Logical Database Design and the Relational Model.
Ch 7: Normalization-Part 1
©Silberschatz, Korth and Sudarshan2.1Database System Concepts Chapter 2: Entity-Relationship Model Entity Sets Relationship Sets Mapping Constraints Keys.
Chapter 2: Entity-Relationship Model. 3.2 Chapter 2: Entity-Relationship Model Design Process Modeling Constraints E-R Diagram Design Issues Weak Entity.
©Silberschatz, Korth and Sudarshan7.1Database System Concepts - 6 th Edition Chapter 7: Entity-Relationship Model.
CS3431: C-Term Translating ER Schema to Relational Model Instructor: Mohamed Eltabakh
FEN Introduction to the database field: The development process Seminar: Introduction to relational databases Development process: Analyse.
IT 5433 LM3 Relational Data Model. Learning Objectives: List the 5 properties of relations List the properties of a candidate key, primary key and foreign.
Functional Dependencies and Normalization 1 Instructor: Mohamed Eltabakh Part 2.
Chapter 2: Entity-Relationship Model
COP Introduction to Database Structures
Translating ER Schema to Relational Model
Chapter 5: Logical Database Design and the Relational Model
Entity-Relationship Model
Chapter 2: Entity-Relationship Model
CS411 Database Systems 08: Midterm Review Kazuhiro Minami 1.
Tables and Their Characteristics
Quiz Questions Q.1 An entity set that does not have sufficient attributes to form a primary key is a (A) strong entity set. (B) weak entity set. (C) simple.
Payroll Management System
From ER to Relational Model
Functional Dependencies and Normalization
Module 5: Overview of Normalization
Functional Dependencies and Normalization
Functional Dependencies and Normalization
Session 2 Welcome: The seventh learning sequence
Instructor: Mohamed Eltabakh
Chapter 6: Entity-Relationship Model
Instructor: Mohamed Eltabakh
Chapter 7: Entity-Relationship Model
Instructor: Mohamed Eltabakh
Chapter 7a: Overview of Database Design -- Normalization
Functional Dependencies and Normalization
Functional Dependencies and Normalization
Presentation transcript:

Announcements Midterm is Nov. 22 (8:15am – 9:45am) Covers until the end of Normalization You answer in the same exam paper Closed-Book, One sheet is allowed for your notes 1

Revision Instructor: Mohamed Eltabakh 2

Covered Topics Entity-Relationship Model & ERD Relational Model Relational Algebra Functional Dependencies & Normalization 3

Relational Algebra 4

Key Points Understand the meaning of each operator and what it does, E.g., Selection (σ c ): selects certain tuples based on a condition (all columns) Projection (π k ): selects certain columns (All tuples) Join ( ⋈ C ): joins tuples from one relation with another relation based on a condition Practice how to combine these operators to answer queries Performance rules: Apply selection earlier whenever possible Use joins instead of Cartesian product Avoid un-necessary joins 5

Relational Algebra: Exercise Ships having the same design belong to the same class. The class information is stored in “ShipClass”. The ship information is stored in “WarShips” Each ship may participate in multiple missions. The mission information is stored in “Missions” Each ship in a mission has a status as either ‘damaged’, ‘sunk’, or ‘ok’. This information is stored in “Results” 6 ShipClass(name, type, country, numGuns, designYear, weight) WarShips(shipName, className, builtYear) Missions(missionName, date) Results(shipName, missionName, status) ShipClass(name, type, country, numGuns, designYear, weight) WarShips(shipName, className, builtYear) Missions(missionName, date) Results(shipName, missionName, status) Write the algebraic expression for the following queries

Query 1 7 For classes with at least 10 guns, report the class name and country; π name,country (σ numGuns >= 10 (ShipClass))

Query 2 8 List the warShips built after 1932 σ builtYear > 1932 (WarShips)

Query 3 9 Report the names of ships damaged in the mission of “Sun Rising”. π shipName (σ missionName= ‘Sun Rising’ AND status=‘damaged’ (Results))

Query 4 10 Suppose there was an agreement prohibiting war-ships heavier than 40,000 tons. Report the ship names and built year of ships violating this agreement. π shipName,builtYear (σ weight > 40,000 (ShipClass ⋈ name=className WarShips)) π shipName,builtYear (σ weight > 40,000 (ShipClass) ⋈ name=className WarShips) Better

Query 5 11 Continue from the previous query, Find the ships that violate the agreement the least (i.e., the lightest ships violating the agreement) R1  π ID (σ FirstName = ‘John’ AND LastName=‘Smith’ (Doctor) ⋈ SSN=Doctor_SSN Prescription) R2  π ID  Prescription_id (σ TradeName=‘Aspirin’ (Prescription_Medicine)) ∩ R1 Result   (π Pateint_SSN ( R2 ⋈ Prescription))

Query 6 12 In the mission of “Sun Rising”, find the name and weight of the ships involved R1  π shipName (σ missionName = ‘Sun Rising’ (Results)) Result  π R1.shipName, weight (R1 ⋈ R1.shipName=Warships.shipName WarShips ⋈ className=name ShipClass)

Query 7 13 Report ship name for ships that were ‘ok’ in one mission, but later ‘sunk’ in another. π shipName (σ status = ‘sunk’ (Results)) ∩ π shipName (σ status = ‘ok’ (Results))

ER & Relational Models 14

Key Points Remember the notations used in ERD Relationships cardinalities (1-1, 1-M, M-M) Entity sets and weak entity sets Primitive, derived, and composite attributes Mapping rules from ERD to relational model, E.g., M-M relationship  separate table 1-M relationship  take the key from the one-side to the many-side 1-1 relationship  take the key from either sides to the other side ISA relationship  Many choices depending on its type Remember to indicate the integrity constraints, most important are: Primary keys, Foreign keys 15

Airline Application We have a set of planes, each plane can make many flights. Each plane has properties such as: ID (unique identifier), model, capacity, year in which it is built, and weight Each flight has a departure city, arrival city, and it can make transit in many other cities. Also each flight has the departure date, arrival date, and the transit date in each of the transit cities (assume the ‘date’ captures both the date and exact time). Each flight has some properties such as: FlightNum (unique identifier), number of transit stops, number of passengers For each city, we have an CityID (unique identifier), name, and country 16

Question 1 Design an ER diagram for the given application. The diagram must include: The entity sets, attributes, primary keys The relationships with the correct cardinalities State any assumptions that you make and affect your design 17

18 Plane year ID model capacit y weight City CityID countryname Flight FNum NumStops Num Passengers makes transit date arrival Arrival date departure date Assumption: The entire flight is done by a single plane

Question 2 Extend your ERD in the previous question to capture the following additional requirements: Each flight has one captain, one assistant captain, and between 2 to 4 flight attendants Each of the captain, assistant captain, and attendants have a common set of properties such as: EmployeeID (unique identifier), name, salary, and DoB The same person can be captain on some flights and assistant captain on other flights (basically same person can have different roles (captain or assistant captain) in different flights). 19

20

Question 3 Map the ERD from the previous question (Question 2) to the corresponding relational model Provide the CREATE TABLE commands with the field names and appropriate data types Identify the primary keys and foreign keys in the relations 21

Relational Model 22 Create Table Plane ( ID: int Primary Key, Year: int, Capacity: int, Weight: int, Model: varchar(50)); Create Table City( ID: int Primary Key, Name: varchar(100), Country: varchar(100)); Create Table Flight( FNum: varchar(8) Primary Key, NumStops: int, NumPassengers: int, PlaneID: int Foreign Key References Plane(ID), ArrivalCityID: int Foreign Key References City(CityID), DepartCityID: int Foreign Key References City(CityID), ArrivalDate: date, DepartDate: date, CaptainID: int Foreign Key References Employee (ID), AssistID: int Foreign Key References Employee (ID)); Create Table Employee ( ID: int Primary Key, name: varchar(100), DOB: int, Salary: int, JobTitle: varchar(100) check JonTitle in (‘Captain’, ‘Attendant));

Relational Model (Cont’d) 23 Create Table Transit ( FNum: int Foreign Key References Flight(FNum), CityID: int Foreign Key References City(CityID), TransitDate: date, Primary Key (Fnum, CityID)); Create Table Flight_Attendant( FNum: int Foreign Key References Flight(FNum), AttendantID: int Foreign Key References Employee(ID), Primary Key (Fnum, EmpID));

Relational Model (Cont’d) Assumptions: The ISA relationship is modeled using one table “Employee” Whether the employee is Captain or Attendant is modeled using a new attribute “JobTitle” Business Constraints: Attributes CaptainID and AssistID in “Flight” must correspond to employee with job title “Captain” Attribute AttendantID in “Flight_Attendant” must correspond to employee with job title “Attendant” Attribute NumPassengers in “Flight” must be less than or equal to attribute Capacity in “Plane” 24

Functional Dependencies & Normalization 25

Key Points Identifying the candidate keys of relations Use of Transitive, and Union properties to generate more FDs Computing the attribute closure A is a key if all attributes are in its closure A candidate key is also a super key (But it is minimal) Remember the rules for BCNF and 3NF Test which FD is violating the rules Decompose based on this rule 26

Question 1 Given relation R= (A, B, C, D, E) with the following FDs: F = {AB  C, C  D, B  D, CD  E, AB  E} Compute the canonical (minimal) cover of F = G What are the candidate keys of R? 27 G = {AB  C, C  DE, B  D} AB

Question 2 Given relation R = (A, B, C, D) with the following FDs: F = {B  C, B  D} What are the candidate keys of R? Report FDs violating BCNF (if any)? Decompose R to be in BCNF (if not already)? 28 AB B  C B  D

Question 2 (Cont’d) Given relation R = (A, B, C, D) with the following FDs: F = {B  C, B  D} What are the candidate keys of R? Report FDs violating 3NF (if any)? Decompose R to be in 3NF (if not already)? 29 AB B  C B  D