Sie sind auf Seite 1von 17

Database Design - Structure

Conceptual
model

Logical
model

Physical
model

- General (not attached to any model)


- Not normalized
- e.g. ER diagram, still has M:N relationships, composite &
multivalued attributes
- Specific to data model, e.g. relational data model
- Normalized
- e.g. ER diagram, only has 1:1 & 1:M relationships
normalized relational schema
- Specific to DBMS
- e.g. Oracle, CREATE TABLE statement

Revisit the ERD


Look for M:N relationships change the diamond into rectangle
symbol. Create a new relationship from entity1 to the newly
created entity with 1:M connectivity & from the newly created
entity to entity2 with M:1 connectivity.
Look for multivalued attributes create a new entity for the
attribute. Create a key attribute for the new entity. Link the
original entity with the newly created entity with 1:M connectivity
if each value is unique to an instance, otherwise M:N
Look for composite attributes if each sub-attributes value is
unique for each instance, then include each sub-attribute in the
entity. Otherwise, create a new entity, and link the new entity to
the original with connectivity M:1.
2

Mapping of ER Diagram to
Relational Database
Schema

Lesson Outcomes
By the end of the lesson, the students should be able to:
Explain some of the terminologies used in relational
database
Map an ER diagram to relational database schema.

Relational Database Terminologies


Relational Database is a collection of normalized relations
with distinct relation names.
A relation is a table with columns and rows.
Normalized is defined as conform to a norm or standard
Merriam-Webster dict. In database, it means no unnecessary
redundancies.
An attribute is a named column/field of a relation.
Domain is the set of allowable values for one or more
attributes.
5

Unnormalized vs Normalized Relations


Unnormalized relation
StudentID
16227
15113
15661
16227

Name
Ali
Chong
Peter
Ali

14355
14111

Elaine
Kumar

ProgCode Program
ICT
Info & Comm. Technology
BIS
Business Information Systems
ICT
Info & Comm. Technology
BIS
Business Information Systems
Electrical & Electronic
EE
Engineering
BIS
Business Information Systems

Year
1
2
2
1
3
3

Normalized relations
StudentID Name
16227 Ali
15113 Chong
15661 Peter
16227 Ali
14355 Elaine
14111 Kumar

ProgCode Year
ICT
1
BIS
2
ICT
2
BIS
1
EE
3
BIS
3

ProgCod
e
Program
ICT

Info & Comm. Technology

BIS

Business Information Systems

EE

Electrical & Electronic Engineering

Relational Database Terminologies


Tuple is a row/record of a relation.
Degree is the number of attributes in a relation.
Cardinality is the number of tuples in a relation.

Pearson Education Limited 1995, 2005

Relational Database

tuple

What is database schema?


Database schema is the structure of the database when
presented according to the database model chosen.
For relational database, each entity in an ERD will become a
relation.
Each relation will have its relation schema
A relation schema shows the name of the relation along with
all of its attributes which include:

Relation name
Attribute names
Primary key
Foreign key an attribute or set of attributes, within one relation that
matches primary key of some (possibly same) relation.
9

Properties of Relations
Relation name is distinct from all other relation names in
relational schema.
Each cell of relation contains exactly one atomic (single) value.
Each attribute has a distinct name.
Values of an attribute are all from the same domain.
Each tuple is distinct; there are no duplicate tuples.
Order of attributes and tuples in a relation has no significance.

Pearson Education Limited 1995, 2005

10

Steps to map ERD to relational database


schema

Begin with an entity which has 1


connectivity on its side.
Write : Entity_name, (, attributes, ).

attr1a
ENT1

rel1

ENT1 (attr1a, attr1b)

attr1b

Underline the primary key

Continue with other entities (1 on


their side)

ENT1 (attr1a, attr1b)

11

Contd
Next, select an entity with M on its
side (in M:1 relationship)
Write: Entity_name, (, attributes, the
key of the 1 side, )
attr1a
ENT1

rel1

attr1b

attr2a
ENT2
attr2b

ENT2 (attr2a, attr2b, attr1a)

Underline the primary key

ENT2 (attr2a, attr2b, attr1a)

Circle the foreign key


ENT2 (attr2a, attr2b, attr1a)

Continue with similar entities

12

Contd
Next, select the M:N relationship
Write: a relation name to represent the
relationship, (, p.k. of entity1, p.k. of
entity2, attributes if any, )

ENT2

rel2

ENT3 (attr3a, attr3b)


ENT23 (attr2a, attr3a, attr23a)

attr23a
attr2a

ENT2 (attr2a, attr2b)

attr3a
ENT3

attr2b
Underline the two keys, i.e.,
primary/composite key

attr3b

Circle each item of the composite key


for foreign key

ENT23 (attr2a, attr3a, attr23a)

Continue with similar relationships

ENT23 (attr2a, attr3a, attr23a)

13

Contd - extra
If any of the entity has multivalued
attribute, then:
attr1a
ENT1

rel1

ENT1b(attr1ba, attr1b)

attr1b

create a new relation, create a key


attribute and put the multivalued attribute
in the new relation.
Option 1: if each tuple of the new relation
is only for one tuple of the original relation
(1:1 or M:1), then
delete the multivalued attribute from the original
relation
add the key of the original relation into the new
relation. Circle the attribute for foreign key.

ENT1(attr1a)
ENT1b(attr1ba, attr1b, attr1a)

14

Contd - extra
Option 2: if each tuple of the new
relation might be linked to many
tuples of the original relation,
vice-versa (M:N), then
delete the multivalued attribute from
the original relation.
create another new relation. Fill it up
with the keys from both the original
relation and the created relation
earlier.

ENT1(attr1a)
ENT11b(attr1a, attr1ba)

15

Contd - extra
If any of the entity has composite attribute, then:
attr1a
ENT1

rel1

attr1b
attr1b1

attr1b2

create a new relation, create a key attribute and list out all subattributes in the new relation.
ENT1b(attr1ba, attr1b1, attr1b2)

Replace the composite attribute of the original relation with the


key of the new relation. Circle the attribute for foreign key
ENT1(attr1a, attr1ba)

16

Lesson Summary
Relational database schema represents the ERD in the
relational data model
Each entity will create a relation schema, so is the M:N
relationship, multivalued attribute and composite attribute.

17

Das könnte Ihnen auch gefallen