Announcements - PowerPoint PPT Presentation

About This Presentation
Title:

Announcements

Description:

Title: Data Modeling using XML Schemas Author: pcguest Last modified by: Mohamed Eltabakh Created Date: 4/4/2003 7:16:57 PM Document presentation format – PowerPoint PPT presentation

Number of Views:44
Avg rating:3.0/5.0
Slides: 30
Provided by: pcguest
Learn more at: http://web.cs.wpi.edu
Category:

less

Transcript and Presenter's Notes

Title: Announcements


1
Announcements
  • Midterm is Nov. 22 (815am 945am)
  • Covers until the end of Normalization
  • You answer in the same exam paper
  • Closed-Book, One sheet is allowed for your notes

2
Revision
  • Instructor Mohamed Eltabakh
  • meltabakh_at_cs.wpi.edu

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

4
Relational Algebra
5
Key Points
  • Understand the meaning of each operator and what
    it does, E.g.,
  • Selection (sc) selects certain tuples based on a
    condition (all columns)
  • Projection (pk) 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

6
Relational Algebra Exercise
ShipClass(name, type, country, numGuns,
designYear, weight) WarShips(shipName,
className, builtYear) Missions(missionName,
date) Results(shipName, missionName, status)
  • 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

Write the algebraic expression for the following
queries
7
Query 1
For classes with at least 10 guns, report the
class name and country
pname,country (snumGuns gt 10(ShipClass))
8
Query 2
List the warShips built after 1932
sbuiltYear gt 1932(WarShips)
9
Query 3
Report the names of ships damaged in the mission
of Sun Rising.
pshipName (smissionName Sun Rising AND
statusdamaged (Results))
10
Query 4
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.
pshipName,builtYear (sweight gt 40,000(ShipClass
?nameclassName WarShips))
pshipName,builtYear (sweight gt 40,000(ShipClass)
?nameclassName WarShips)
11
Query 5
R1 ?pID(sFirstName John AND
LastNameSmith(Doctor) ?SSNDoctor_SSN
Prescription) R2 ?pID?Prescription_id(sTradeName
Aspirin(Prescription_Medicine)) n R1 Result ?
?(pPateint_SSN( R2 ? Prescription))
Continue from the previous query, Find the ships
that violate the agreement the least (i.e., the
lightest ships violating the agreement)
12
Query 6
In the mission of Sun Rising, find the name and
weight of the ships involved
R1 ?pshipName(smissionName Sun
Rising(Results)) Result ? pR1.shipName, weight
(R1 ?R1.shipNameWarships.shipName WarShips

?classNamename ShipClass)
13
Query 7
Report ship name for ships that were ok in one
mission, but later sunk in another.
pshipName(sstatus sunk(Results)) n

pshipName(sstatus ok(Results))
14
ER Relational Models
15
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

16
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

17
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

18
Assumption The entire flight is done by a single
plane
19
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).

20
(No Transcript)
21
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

22
Relational Model
Create Table Employee ( ID int Primary
Key, name varchar(100), DOB int, Salary
int, JobTitle varchar(100) check
JonTitle in (Captain, Attendant))
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), ArrivalCityI
D int Foreign Key References City(CityID), Depart
CityID int Foreign Key References
City(CityID), ArrivalDate date, DepartDate
date, CaptainID int Foreign Key References
Employee (ID), AssistID int Foreign Key
References Employee (ID))
23
Relational Model (Contd)
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))
24
Relational Model (Contd)
  • 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

25
Functional Dependencies Normalization
26
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

27
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?

G AB ? C, C ? DE, B?D
AB
28
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)?

AB
B ? C B ? D
29
Question 2 (Contd)
  • 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)?

AB
B ? C B ? D
Write a Comment
User Comments (0)
About PowerShow.com