Database Chapter02-02
Transcript of Database Chapter02-02
-
8/10/2019 Database Chapter02-02
1/42
CHAPTER 2
DATABASE DESIGN
1
Database Application
SAK 3408
-
8/10/2019 Database Chapter02-02
2/42
Learning Objectives (W3)2
Describe the database design phases.
Explain on how to construct E-R diagram.
Transform ERD into Relation.
Use normalization to decompose a relationwith anomalies into well-structured relations.
-
8/10/2019 Database Chapter02-02
3/42
Relation3
Definition: A relation is a named, two-dimensionaltable of data
Table is made up of rows (records), and columns (attribute orfield)
Not all tables qualify as relations Requirements:
Every relation has a unique name.
Every attribute value is atomic (not multivalued, notcomposite)
Every row is unique (cant have two rows with exactly thesame values for all their fields)
Attributes (columns) in tables have unique names
The order of the columns is irrelevant
The order of the rows is irrelevant
-
8/10/2019 Database Chapter02-02
4/42
What is atomic value?4
OrderID CustID Date Items
1 4 4/11/02 5 Pencils, 3 Erasers, 6 Rulers
2 23 6/11/02 1 Scissor
3 15 7/11/02 2 Pen, 2 Notebook
4 2 7/11/02 15 5" Magazine File
5 23 7/11/02 1 Stapler
6 2 8/11/02 5 Kingston USB Flash Drive 8GB
This mean that in your table, for every row-by-column
position (cell), there exists only one value - not an
array or list of values:
-
8/10/2019 Database Chapter02-02
5/42
Is this a relation?5
OrderID CustID Date Quantity Items
1 4 4/11/02 5 Pencils
1 4 4/11/02 3 Erasers
1 4 4/11/02 6 Rulers
2 23 6/11/02 1 Scissor
3 15 7/11/02 2 Pen
3 15 7/11/02 2 Notebook
4 2 7/11/02 15 5" Magazine File
5 23 7/11/02 1 Stapler
6 2 8/11/02 5 Kingston USB Flash Drive 8GB
-
8/10/2019 Database Chapter02-02
6/42
-
8/10/2019 Database Chapter02-02
7/42
-
8/10/2019 Database Chapter02-02
8/42
-
8/10/2019 Database Chapter02-02
9/42
-
8/10/2019 Database Chapter02-02
10/42
Transforming E-R into Relations10
Step 1: Mapping Regular Entities to Relations
1. Simple attributes: E-R attributes map directly onto
the relation
2. Composite attributes: Use only their simple,
component attributes
3. Multi-valued Attribute - Becomes a separate
relation with a foreign key taken from the superiorentity
-
8/10/2019 Database Chapter02-02
11/42
(a) CUSTOMER entity
type with simpleattributes
Figure 2.12 Mapping a regular entity
(b) CUSTOMER relation
-
8/10/2019 Database Chapter02-02
12/42
(a) CUSTOMER entity
type with composite
attribute
Figure 2.13 Mapping a composite attribute
(b) CUSTOMER relation with address detail
-
8/10/2019 Database Chapter02-02
13/42
Figure 2.14 Mapping a multivalued attribute
1 to many relationship between original entity and new relation
(a)
Multivalued attribute becomes a separate relation with foreign key
(b)
-
8/10/2019 Database Chapter02-02
14/42
Transforming E-R into Relations14
Step 2: Mapping Weak Entities
Becomes a separate relation with a
foreign key taken from the superiorentity
Primary key composed of:
Partial identifier of weak entityPrimary key of identifying relation (strong
entity)
-
8/10/2019 Database Chapter02-02
15/42
Figure 2.15 Mapping a weak entity
(a) Weak entity DEPENDENT
-
8/10/2019 Database Chapter02-02
16/42
-
8/10/2019 Database Chapter02-02
17/42
Transforming E-R into Relations17
Step 3: Mapping Binary
Relationships
One-to-Many - Primary key on the one sidebecomes a foreign key on the many side
Many-to-Many - Create a new relationwith the
primary keys of the two entities as its primary
keyOne-to-One - Primary key on the mandatory
side becomes a foreign key on the optional
side
-
8/10/2019 Database Chapter02-02
18/42
Figure 2.16 mapping a 1:M relationship
(a) Relationship between customers and orders
-
8/10/2019 Database Chapter02-02
19/42
(b) Mapping the relationship
Again, no null value in theforeign keythis is
because of the mandatory
minimum cardinality
Foreign key
-
8/10/2019 Database Chapter02-02
20/42
Figure 2.17 Mapping M:N relationship
(a) ER diagram (M:N)
The Suppliesrelationship will need to become a separate relation
-
8/10/2019 Database Chapter02-02
21/42
(b) Three resulting relations
Newintersection
relationForeign key
Foreign key
Composite primary key
-
8/10/2019 Database Chapter02-02
22/42
Figure 2.18 Mapping a binary 1:1 relationship
(a) Binary 1:1 relationship
-
8/10/2019 Database Chapter02-02
23/42
-
8/10/2019 Database Chapter02-02
24/42
Transforming E-R into Relations24
Step 4: Mapping Associative Entities
Identifier Not Assigned
Default primary key for the association relation is
composed of the primary keys of the two entities (as inM:N relationship)
Identifier Assigned
It is natural and familiar to end-users
Default identifier may not be unique
-
8/10/2019 Database Chapter02-02
25/42
Figure 2.19 Mapping an associative entity
(a) Associative entity
-
8/10/2019 Database Chapter02-02
26/42
(b) Three resulting relations
-
8/10/2019 Database Chapter02-02
27/42
-
8/10/2019 Database Chapter02-02
28/42
Figure 2.20 Mapping a unary 1:N relationship
(a) EMPLOYEE entity
with Manages
relationship
(b) EMPLOYEE
relation with
recursive foreign
key
-
8/10/2019 Database Chapter02-02
29/42
29
Mapping a unary M:N relationship
(a) Bill-of-materials
relationships (M:N)
(b) ITEM andCOMPONENT
relations
-
8/10/2019 Database Chapter02-02
30/42
Transforming E-R into Relations30
Step 6: Mapping Ternary (and n-ary)
Relationships
One relation for each entity and one for theassociative entity
Associative entity has foreign keys to each
entity in the relationship
-
8/10/2019 Database Chapter02-02
31/42
Figure 2.21 Mapping a ternary relationship
(a) Ternary relationship with associative entity
-
8/10/2019 Database Chapter02-02
32/42
(b) Mapping the ternary relationship
Remember that the primary
key MUST be unique
-
8/10/2019 Database Chapter02-02
33/42
Transforming E-R into Relations33
Step 7: Mapping Supertype/Subtype
Relationships One relation for supertype and for each subtype
Supertype attributes (including identifier and subtype
discriminator) go into supertype relation
Subtype attributes go into each subtype; primary key of
supertype relation also becomes primary key of subtype
relation
1:1 relationship established between supertype and
each subtype, with supertype as primary table
-
8/10/2019 Database Chapter02-02
34/42
Figure 2.22 Supertype/subtype relationships
(a)
-
8/10/2019 Database Chapter02-02
35/42
-
8/10/2019 Database Chapter02-02
36/42
Exercise (1)36
phone
-
8/10/2019 Database Chapter02-02
37/42
Exercise (2)37
-
8/10/2019 Database Chapter02-02
38/42
Exercise (3)38
-
8/10/2019 Database Chapter02-02
39/42
Exercise (4)39
-
8/10/2019 Database Chapter02-02
40/42
Exercise (5)40
-
8/10/2019 Database Chapter02-02
41/42
Exercise (6)
Game
Name Graphics Sound
Gameplay Platform
Developer
Name
Phone no
Rater
Name
Ability
rates by
41
-
8/10/2019 Database Chapter02-02
42/42
Exercise (7)42