Top Banner
1 Database Course Database Course
50

1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

Dec 21, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

1

Database CourseDatabase Course

Page 2: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

2

General InformationGeneral Information

• TAs:

– Gideon Rothschild, office hours: Sun 16:00-17:00 at Ross 109

– Aron Matskin, office hours: TBA

• Course Homepage: http://www.cs.huji.ac.il/~db

• Course Email: [email protected]

• Moderated Newsgroup: local.course.db.ta

• Students Newsgroup: local.course.db.stud

Page 3: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

3

TA LecturesTA Lectures

• Tue – Wed – Sun cycle• Same TA during the cycle• If a TA lecture falls out on a holiday,

students should plan to attend another lecture during the same cycle

• Students are responsible for all the material for the final exam. That includes lectures, TA lectures, slides, and homework

Page 4: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

4

Assignments (1)Assignments (1)

• About 10-12 assignments• Assignments are 25% of the final grade• All assignments must be handed in!• Assignments are to be done alone

(not in pairs)!• Must include name, login, student

number. Points will be taken off if login is omitted

Page 5: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

5

Assignments (2)Assignments (2)

• Assignment submission:– Theoretical assignments - box in Ross

-2– Programming assignments -

electronically • Assignments are returned in Ross –2,

grades available on the internet• Make sure that you have a grade when

the exercise is returned!

Page 6: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

6

Appeals and ExtensionsAppeals and Extensions

• Appeals are submitted to box in Ross -2

• Appeal form available on the course site

• Appeals should be submitted no later than

1 week after assignments are returned

• Extensions are possible in special cases (i.e.,

miluim, childbirth, etc.).

• Ask for the extension before the due date

Page 7: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

7

Course BooksCourse Books

• Database Management Systems, by Raghu

Ramakrishnan

• Principles of Database and Knowledge-

Base Systems, Volumes I and II, by Jeffery

Ullman (essentially chapter 7 concerning

Design Theory)

• Oracle 8i: The Complete Reference, by

Kevin Loney and George Koch

Page 8: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

8

Entity-Relationship DiagramsEntity-Relationship Diagrams

Database Course, Fall 2005

Page 9: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

9

ScenarioScenario

• http://www.imdb.com wants to maintain a

movie database

• The design approach we now consider:

– Conceptual Database Design: high level

description of data to be stored (ER model)

– Logical Database Design: translation of ER

diagrams into a relational database schema

(description of tables)

Page 10: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

10

Movie Database Requirements Movie Database Requirements (1)(1)

• For actors and directors, we want to store their name, a unique identification number, address, and birthday

• For actors, we also want to store a picture

• For movies, we want to store the title, year of production, and type

• We want to know who directed and who acted in each movie. Every movie has one director

• We store the pay of each actor for each movie

Page 11: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

11

Movie Database Requirements Movie Database Requirements (2)(2)

• An actor can receive an award for his part in a movie. We store information about who got which award for which movie, along with the name of the award and year.

• We also store the name and telephone number of the organization that gave the award. Two different organizations can give an award with the same name. A single organization does not give more than one award with a particular name in the same year.

Page 12: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

12

Entities, Entity SetsEntities, Entity Sets

• Entity (ישות): An object in the world that can be

distinguished from other objects

• Entity set ( ישויות A set of similar entities :(קבוצת

Entity sets are drawn as rectangles

• Compare to objects and classes in OOD

Q: What are some of the entity sets in our

movie database?

Page 13: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

13

AttributesAttributes

• Attributes (תכונות): Used to describe

entities

– All entities in the set have the same

attributes

Attributes are drawn using ovals

– A minimal set of attributes that uniquely

identify an entity is called a key

The names of the attributes which make

up the key are underlined

Page 14: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

14

ExampleExample

Actorid

name address

birthday

Page 15: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

15

Another Option for a Key?Another Option for a Key?

Actorid

name address

birthday

Page 16: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

16

Relationships, Relationship SetsRelationships, Relationship Sets

• Relationship (קשר): Association among two or more entities

– Relationships may have attributes

• Relationship Set ( קשרים Set of :(קבוצתsimilar relationshipsRelationship sets are drawn using

diamonds

Q: Could you name some of the relationship sets in the movie database?

Page 17: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

17

ExampleExample

Actorid

name

address

birthday

Acted In Movie

title

type

year

Where does the salary attribute belong?

salary

Page 18: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

18

Recursive RelationshipsRecursive Relationships

Employeeid

name

address

phone number

Manages

• An entity set can participate more than once in a relationship

• In this case, we add a description of the role to the ER-diagram

manager

worker

Page 19: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

19

nn-ary Relationship-ary Relationship

• An n-ary relationship set R involves exactly n

entity sets: E1, …, En

• Each relationship in R involves exactly n

entities: e1E1, …, en En

• Formally, R E1x …x En

Actorid

name

Produced Movie title

Directorid name

Page 20: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

20

Another Option: Another Option: Remember Recursive Remember Recursive

RelationshipsRelationships

Person

id

name

titleproduce

d Movie

director

actor

Page 21: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

21

Binary vs. Ternary Binary vs. Ternary RelationshipRelationship

קורסמרצה לימד

שם קורס שם מרצה מספר קטלוגימס זהות

שם מוסדמוסד

קורסמרצה

לימד ב

שם קורס שם מרצה מספר קטלוגימס זהות

מוסד

שם מוסד

לימד את

ניתן ב

Page 22: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

22

Important NoteImportant Note

id

name

Actor Acted In Movie

• The entities in a relationship set identify the relationship

• Suppose we wanted to store the role of an actor in a movie

• How would we store information about a person who acted in one movie in several roles?

role

titleRole

title

Page 23: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

25

Key Constraints (Key Constraints ( אילוצי אילוצי((מפתחמפתח

• Key constraints specify whether an entity can

participate in one, or more than one, relationships in

a relationship set

• When there is no key constraint, an entity can

participate any number of times

• When there is a key constraint, the entity can

participate at most one time

Key constraints are drawn using an arrow from the

entity set to the relationship set

Page 24: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

26

Many-to-ManyMany-to-Many

A movie is directed by any number of directors

A director can direct any number of movies

Directorid

name

Directed Movie title

Director Directed Movie

Page 25: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

27

One-to-ManyOne-to-Many

A movie is directed by at most one director

A director can direct any number of movies

Directorid

name

Directed Movie title

Director Directed Movie

Page 26: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

28

One-to-OneOne-to-One

A movie is directed by at most one director

A director can direct at most one movie

Directorid

name

Directed Movie title

Director Directed Movie

Page 27: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

29

Another ExampleAnother Example

Personid

name

age

FatherOf

Where would you put the arrow?

father

child

Page 28: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

30

Another ExampleAnother Example

Personid

name

age

FatherOf

father

child

Page 29: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

31

Key Constraints in Key Constraints in Ternary RelationshipsTernary Relationships

Directorid

name

produced Movie title

Actorid name

What does this mean?

A movie has at most one actor and one director

Page 30: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

32

Participation Constraints Participation Constraints השתתפות השתתפות אילוצי ((((אילוצי

• When there is no participation constraint, it

is possible that an entity will not participate

in a relationship set

• When there is a participation constraint, the

entity must participate at least once

Participation constraints are drawn using a

thick line from the entity set to the

relationship set

Page 31: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

33

Example (1)Example (1)

• A movie has at least one director

• A director can direct any number of movies

Directorid

name

Directed Movie title

Director Directed Movie

Do you think that there

should be a participation constraint

from Director to Directed?

Page 32: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

34

Example (2)Example (2)

• We can combine key and participation constraints.

• What does this diagram mean?

Directorid

name

Directed Movie title

A movie has exactly one director.

A director directs at least one movie.

Page 33: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

35

Weak Entity Sets (1)Weak Entity Sets (1)

Award

year name

organization

What is the problem here?

Page 34: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

36

Weak Entity Sets (2)Weak Entity Sets (2)

Award

Organization

Gives

year

name

name

phonenumber

Does this solve the problem?

Page 35: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

37

Weak Entity Sets (3)Weak Entity Sets (3)

• Weak entity sets are entity sets that are

not uniquely identified by their

attributes

• A weak entity set has an "identifying

relationship“ ( זיהוי with an entity (תלות

set that is the "identifying owner“

( המזהה of the weak entity set (הבעלים

Page 36: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

38

Weak Entity Sets (4)Weak Entity Sets (4)

A weak entity set must:– participate fully in the identifying

relationship ( a thick line)

– participate in a one to many relationship with the identifying owner ( an arrow)

Weak entity sets have a thick rectangle, their keys are underlined with a broken line, and the identifying relationship has a thick diamond

Page 37: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

39

Weak Entity Sets (5)Weak Entity Sets (5)

Award

Organization

Gives

year

name

name

phonenumber

Page 38: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

40

ExampleExample

Booktitle

author

isbn

Copy

copy number condition

Copy Of

Borrowed

Person

id

Page 39: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

41

What if We Store What if We Store Information About Many Information About Many

Libraries?Libraries?

Booktitle

author

isbn

Copy

copy number condition

Copy Of

Borrowed

Person

id

Owned ByLibraryname

Page 40: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

42

ISA HierarchiesISA Hierarchies

ISA Relationships: Define a hierarchy

between entity sets

– ISA is similar to inheritance

ISA relationships are drawn as a triangle

with the word ISA inside it. The "super

entity-set" is above the triangle and the

"sub entity-sets" are below

Page 41: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

43

ExampleExample

What are the keys of:

1. Movie Person

2. Actor

3. Director

Movie Person

ISA

Actor

id

name

address

birthday

picture Director

Page 42: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

44

Overlap ConstraintsOverlap Constraints

• Overlap constraints: Determine

whether two sub-entity sets can

contain the same entity

– Example: Can an Actor be a Director?

Write "Actor OVERLAPS Director". If not

written, assume no overlap

Page 43: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

45

Covering ConstraintsCovering Constraints

• Covering constraints: Determine

whether every entity in the super-entity

set is also in at least one of the sub-

entity sets

– Example: Is every movie person either an

Actor or a Director?

Write "Actor AND Director COVER Movie

Person". If not written, assume no covering

Page 44: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

46

child Person Married

name id

ParentOf

parent woman

man

ExampleExample

Is this good?

A man can be married to a man and a woman to a woman!

Page 45: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

47

ExampleExample

Person

ISA

Man Woman

ParentOf

Married

child

parent name

id

Man AND Woman COVER Person

Page 46: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

48

AggregationAggregation

• Aggregation: Allows us to indicate

that a relationship set participates in a

relationship set

Page 47: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

49

Is this good? (1)Is this good? (1)

Actorpicture

Movieyear

typetitle

Acted Insalary

Award

• Each movie has received at least one award

• Each actor has received at least one award

Page 48: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

50

Is this good? (2)Is this good? (2)

Actorpicture

Movieyear

typetitle

Acted Insalary

AwardWon

The same award can be granted to an actor A and to a movie F although the actor A has not acted in the movie F.

Page 49: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

51

Solution: Use AggregationSolution: Use Aggregation

Actorpicture

Movieyear

typetitle

Acted Insalary

Award

Won

Page 50: 1 Database Course. 2 General Information TAs: –Gideon Rothschild, office hours: Sun 16:00- 17:00 at Ross 109 –Aron Matskin, office hours: TBA Course Homepage:

52

Movie Person

ISA

Actor

id

name

address

birthday

picture Director

Movieyear

typetitle

Acted In Directedsalary

Award

Organization

Gives

year

name

name

phonenumber

Won