Database Management Systems
Course 236363 Faculty of Computer Science Technion – Israel Institute of Technology
Database Management Systems Course 236363 Lecture 2: - - PowerPoint PPT Presentation
Faculty of Computer Science Technion Israel Institute of Technology Database Management Systems Course 236363 Lecture 2: Entity-Relationship Diagrams Outline Introduction ER Diagrams Entities Relationships Weak
Course 236363 Faculty of Computer Science Technion – Israel Institute of Technology
3
4
– What information needs to be stored? How will it be used? What integrity constraints should be imposed?
– Define/describe/discuss the semantic modeling of data in the application (ER model via ER diagrams)
– Translate the ER diagram into a relational DB schema
– Translate the database schema into a a physical storage plan on available hardware (done by DBMS)
5
is associated with a unique movie, etc.
6
7
– Need to thoroughly understand it to correctly design and interpret diagrams
– Facilitates the process of defining the logical level of the data model (e.g., relational schemas) – Translates informal requirements into formal ones
– Differ in visuals and semantics – We will use Garcia-Molina, Ullman & Widom
8
rectangle ellipse rhombus triangle
10
name birthday photo id address Person ISA Actor Director genre year name Directs role PlaysIn Crew WorksFor Studio name Address name Owns Movie 11
An instance has a set of actors, each having an id, a birthday, a photo, ...
13
name
birthday photo id address
Actor
photo id address Actor day month year first middle last name birthday
14
One level; no more
15
name birthday photo
address Actor
16
It is conventional to specify a key for every entity type (unless we have a good reason not to); keys are sometimes “natural” (e.g., SSN) and sometimes artificial (internal identifiers)
name birthday photo id address Actor
17
name birthday photo id address Actor name birthday photo id address Actor
Overly restricted Overly restricted Overly permissive
18
name birthday emp# id address Actor name birthday emp# id address Actor name birthday emp# id address Actor
Can we say that both id and emp# are keys? There is a limit to what we can express with a small set of arrows and shapes
name birthday id address Actor
photo
19
21
name birthday id Actor
PlaysIn genre year name Movie
22
name birthday id Actor
PlaysIn genre year name Movie role
23
(that is, the involved entities form a key for the relationship) What should we do if we want an actor to have multiple roles?
name birthday id Client Purchase id vendor name Product Store address manages name birthday id Employee
24
Ternary relationship type
25
Actor PlaysIn Movie
26
Song MadeFor Movie
27
If we’re given LHS, then we know RHS
A and B are in a many-to-one relationship if each B may have many A, but each A may have at most one B
Studio Owns Movie
28
A and B are in a one-to-many relationship if each B has at most one A, but each A may have many B
Person PresidentOf Studio
29
A and B are in a one-to-one relationship if each B has at most one A, AND each A has at most one B
Role Plays Movie Actor
(Put differently, Movie and Role determine Actor)
30
Owns President
Movie Studio
This is a limitation in ERD expressive power; typical in visual models, since there is only so much we can represent with arrows...
31
Studio Owns Movie
studio may own multiple movies)
32
President Heads Studio
33
Actor StarsIn Movie
<3
Actor PlaysIn Movie
>1
34
Movie Sequel
follows
Person Parents
parent child
name id
35
name birthday id Actor PlaysIn genre year name Movie role Awarded Award name
36
Crew WorksFor Studio name Address name
38
Can there be two crews with the same name (e.g., Crew 1)? Makes sense within a studio; but outside?
39
Company BC Battalion number number name Crew WorksFor Studio name Address name
40
“Weak Entity” “Identifying Relationship” “Identifying
Crew WorksFor Studio name Address name
41
Can there be two crews with the same name? What info uniquely identifies a crew?
Company BC Battalion number number name Company BC Battalion number number name Company Battalion number number name BC
42
43
Contract CA Actor number id name CS Studio address name birthday
The existence of Contract depends on BOTH Actor and Studio
date
45
name birthday photo id address Person ISA Actor Director
46
A ISA C B
47
A ISA B Specialization
48
A ISA B Generalization C
Some As are Bs, Bs are As An A is either a B or a C
50
51
Actor PlaysIn Movie salary
52
Movie ActsIn Actor Rep Agency ActsIn Actor Movie Agency
53
Movie ActsIn Actor Rep Agency
Studio Owns name studioName Movie
studioID studioAddress studioName studioManager Movie
54
address id Person
55
name id Person name
LivesIn
Property value address
salary birthday id MoviePerson ISA Actor Director Person ISA
56
58
59
integers (≥0) integers (>1800, <3000) strings (length≤1024) strings (length≤1024) {‘G’, ‘PG’, ‘PG-13’, ‘R’, ‘NC-17’}
60
61
Role(actor,movie,role) Actor(id,name,photo)
62
63
name birthday photo id address Actor
64
name birthday photo id address Actor
65
name birthday id Actor PlaysIn genre year name Movie salary
66
67
CREATE TABLE Actor ( id int, name text, birthday date, PRIMARY KEY (id) ) CREATE TABLE Movie ( name text, year int, genre text, PRIMARY KEY (name,year) ) CREATE TABLE PlaysIn ( aid int, name text, year int, salary int, PRIMARY KEY (aid,name,year), FOREIGN KEY (aid) REFERENCES Actor(id), FOREIGN KEY (name,year) REFERENCES Movie(name,year) )
68
Studio Owns name address genre year name Movie
69
Studio Owns name address genre year name Movie
70
Studio Owns name address genre year name Movie
71
Studio Owns name address genre year name Movie
72
73
Crew WorksFor Studio name address name
room
74
name birthday photo id Person ISA Actor Director
75
project
just the project to which the employee belongs
ETP
EP
EP
77
EP ETP T E P
A higher level entity type