Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
Chapter 2:
Introduction To Database Design
“The Entity-Relationship Model”
2
Overview of Database Design
3
Overview of Database Design
4
Overview of Database Design
Purpose of model:
•Models help communicate the concepts that are in
people’s minds.
•contains sufficient detail for a developer to build a
database system
5
2.1 Database Design And Er Diagrams
The database design process can be divided to six steps, The ER
model is most relevant to the first three steps:
1. Requirements Analysis
–The first step in designing a database application is to understand what data
to be stored in the database. In other words, we must find out what is the
users want from the database.
2. Conceptual Design
–The information gathered in the requirement analysis step is used to
develop a high-level description of the data stored in the database. This step
is often carried out using Entity relationship (ER) model.
–(Conceptual design is the process of constructing a model of information use
in organization)
3. Logical Database Design
–Working with ER model to produce an initial design for the database to
deliver a model (schema) viewed as relations and tables.
6
2.1 Database Design And Er Diagrams
4. Schema Refinement
• The fourth step analysis the collection of relation to identify potential
problems. Schema refinement make sure the there is no problems in
conceptual analysis. Normalization is used for schema refinement.
5. Physical Database Design
• In this step we must consider typical expected workload that our
database must support and further refine the database design to
ensure that it meets desired performance criteria.
6. Security Design
• In this step we identify different users groups and different roles
played by various users. Also, we identify parts of database the user
or/and role can access
7
Benefit of ER
8
ER Model Basics
2.2 Entities, Attributes, And Entity Sets
• Entity: Real-world object distinguishable from other
objects. An entity is described (in DB) using a set of
attributes.
• Entity Set: A collection of similar entities. E.g., all
employees.
– All entities in an entity set have the same set of
attributes.
– Each entity set has a key. ssn
name
lot
– Each attribute has a domain.
Employees
9
ER Model Basics
2.3 Relationships And Relationship Sets
since
name dname
ssn lot did budget
• In contrast, each
department has at most
one manager, according
to the key constraint on
Manages.
1-to-1 1-to Many Many-to-1 Many-to-Many
11
Weak and Strong entities
12
Weak and Strong entities
13
Relationship
14
One to many (1 : M)
15
One to many (1 : M)
Register in
Student Department
Register in
M 1
Student Department
Register in
∞ 1
Student Department
16
One to many (1 : M)
has
Building Classroom
17
One to one (1:1)
has
19
Many to Many (M:M)
21
Many to Many (M:M)
23
Optionally
24
Recursive
• Logical tables
• EMPLOYEE(empno, empname, empaddr, supervised_by).
• supervised_by references to EMPLOYEE
• Another Example:
Treated
Doctor by
26
Rules for building logical design
1) One to many (1 : M)
– In the 1:M foreign key ALWAYS goes at the many end of
the relationship to avoid repeating groups.
• Example
Registered in
Student Department
27
Rules for building logical design
28
Rules for building logical design
•An employee may drive an organization’s car, place the foreign key
staffno into CAR:
– EMPLOYEE) staffno, staffname, address)
– CAR (registrationno, staffno, make, model(
• Staff_no references EMPLOYEE(staffno(
29
Rules for building logical design
30
Rules for building logical design
3) Many to Many:
– Always need a link entity to show the relationship
regardless of optionality. The link entity primary key is the
combined of the two entities primary keys and it self is a
foreign key. Student
Student Course
course
4) Recursive:
– In recursive the foreign key references the primary key of
the same table.
Supervised
by
Employee
32
Degree of relationship type
Student Course
33
Example of Ternary relationship
34
Example of Ternary relationship
• In this case the linked entity will take the primary key
of the three entities.
– STUDENT (stdentno, student_name, address)
– COURSE (course_no, course_name, grade)
– CLASS_ROOM(c_no, class_location)
– COURSE_STUDENT(student_no, course_no, c_no, class_time)
• Student_no references STUDENT
• Course_no reference COURSE
• C_no references CLASS_ROOM
35
Degree of relationship type
B C
36
Example 1
37
Example 1
M
M
Belongs to
Needs
M
1
Department Part
M
Provides
1
Supplier
38
Example 2
• Each drug is sold by a drug company, drug is only sold by only one
company. For each drug , the trade name and formula must be
recoded. The trade name identified the a drug uniquely from the
product of the company.
• Each patient has only one doctor, each doctor has at least one
patient. Patients are identified by an SSN, and their names ,
addresses, and ages are recorded.
39
Example 2 …
40
Example 2 …
41
Example 2 …
42
Summary of Conceptual Design
43