Database MEF 2021 BC 3
Database MEF 2021 BC 3
Database MEF 2021 BC 3
ER DİAGRAM
COMP 305 DBMS COURSE
LECTURE PLAN
• Quick Review
• More on ER Diagrams
• Some Tips for Better ER Diagrams
• Examples
• Term Projects
2
STEPS IN BUILDING A DB APPLICATION
Pick application
Conceptual design
domain
What data do I
need for my
application
How can I domain?
describe that
data?
3
STEPS IN BUILDING A DB APPLICATION
Pick application
Conceptual design
domain
diagram
SQL & Java/C+
ER
+/etc + user
interface
5
E/R MODEL: ENTITIES AND ENTITY SETS
6
E/R MODEL: ATTRIBUTES
ID Name
• Attributes are:
– Properties of entities Student
• Like fields in a struct
• Like columns in a table/spreadsheet
• Like data members in an object
– Values in some domain (e.g., ints, strings)
• Attributes are simple values, e.g. integers or character strings, not structs, sets, etc.
• Represented by ovals:
7
ER MODEL: RELATIONSHIPS
8
E/R MODEL: RELATIONSHIPS
• Students Enroll in courses
• Courses are Held in rooms
• The E/R data model:
Students Enroll Courses
ID Name Held
Semester
Rooms
9
MULTIPLICITY OF RELATIONSHIPS
• No arrow: many-to-many
• Sharp arrow: many-to-one
• Rounded arrow: “exactly one”
– “key constraint”
• One-one:
10
REPRESENTING “MULTIPLICITY”
• Show a many-one relationship by an arrow
entering the “one” side.
12
EXAMPLE E/R DIAGRAM
Name
Name
ID ID
Assisting
ID TA Name
13
SECOND MULTIWAY E.G.: RENTING MOVIES
Rental Movie
Customer
15
KEYS
• A key is a set of attributes for one entity set such that no two entities in this set agree on all the
attributes of the key.
– It is allowed for two entities to agree on some, but not all, of the key attributes.
• We must designate a key for every entity set.
16
UNDERLINE THE KEY FOR EACH ENTITY SET
name category
multi-attribute keys
price are okay!
Product
Multiple
“candidate keys”?
Pick just one to be Is this a good
the key. Person
key?
17
EXAMPLE: A MULTI-ATTRIBUTE KEY
Courses
18
LECTURE PLAN
• Quick Review
• More on ER Diagrams
• Some Tips for Better ER Diagrams
• Examples
• Term Projects
19
NO KEY?
Weak entity set: some or all of its key attributes
come from other classes to which it is related.
21
Slide from Silberschatz, et al.
E-R DIAGRAM ALTERNATE REPRESENTATIONS
22
Slide from Silberschatz, et al.
ALTERNATIVE ER NOTATIONS
Chen IDE1FX (Crows feet notation)
23
Slide from Silberschatz, et al.
LECTURE PLAN
• Quick Review
• More on ER Diagrams
• Some Tips for Better ER Diagrams
• Examples
• Term Projects
24
FOUR PRINCIPLES OF ER DIAGRAM
• Faithfullness
• Avoid Redundancy
25
FAITHFULNESS
• Is the relationship many-many or many-one?
• Are the attributes appropriate?
• Are the relationships applicable to the entities?
• Examples:
– Courses & instructors
• maybe many-one, maybe many-many
– Bosses & subordinates
• maybe one-many, maybe many-many
26
PRINCIPLE #1:
MODEL YOUR DOMAIN FAITHFULLY
Product Purchase Person
27
PRINCIPLE #2: AVOID REDUNDANCY
• Redundancy = saying the same thing in two (or more) different ways.
• Wastes space and (more importantly) encourages inconsistency.
– Two representations of the same fact become inconsistent if we change one and forget to change the
other.
28
EXAMPLE:
Toys
29
EXAMPLE:
manf
30
PRINCIPLE #3:
DON’T OVERUSE ENTITY SETS
• An entity set should satisfy at least one of the following
conditions:
– It is more than the name of something; it has at least one nonkey
attribute.
or
– It is the “many” in a many-one or many-many relationship.
31
EXAMPLE:
32
EXAMPLE:
name name
33
EXAMPLE:
name manf
Toys
35
WHEN DO WE NEED WEAK ENTITY SETS?
• The usual reason is that there is no global authority
capable of creating unique ID’s.
36
LECTURE PLAN
• Quick Review
• More on ER Diagrams
• Some Tips for Better ER Diagrams
• Examples
• Term Projects
37
EXAMPLES
will be given in the lecture.
38
LECTURE PLAN
• Quick Review
• More on ER Diagrams
• Some Tips for Better ER Diagrams
• Examples
• Term Projects
39
TERM PROJECT TOPIC
• Any realistic topic...
– Any idea that you want to implement
– Any start-up idea in your mind
– In the next semester, an idea that you can implement in
Software Engineering course.
40
TERM PROJECT IMPLEMENTATION
• First of all, create your group with 5 persons.
• Produce realistic scenario as in the examples in this lecture (more
detailed).
• Create your DBMS.
• Write SQL statements.
• Implement a basic user interface
41
TERM PROJECT DELİVERABLES
• You will meet each week and produce a meeting report (who will do
what and when)
• You will deliver one report for scenario and ER Diagram. (Week 7)
• You will deliver another report for everything in your term project.
(Week 14)
• You will also present your work in front of the audiance. (Week 15-16)
42