You are on page 1of 29

Relational data models

Pemodelan Data
Rizka Wakhidatus Sholikah
Outline

• Logical data modeling


• Physical data modeling
• Relational data modeling

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Remember Stages in data modeling

Conceptual Logical Physical


data model data model data model

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Logical data model
• Design independently from DBMS
• list of attributes of each entity must exist
• Each attribute will have datatype
• Each entity has ID as an identifier for each instance
• Example:
Conceptual Logical

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Example
Conceptual

Logical

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Physical data model

• Physical data model specifies for certain DBMS


• Represent the actual blueprint of database design

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Example

• Rules for Entities:


• In physical model, each entity is changed into a table
• The name of entity become the name of table
• The identifier of entity becomes Primary Key (PK)
• There are Foreign Key (FK) that shows the relation between tables
• The datatype is changed to the matching type of matching type in
selected DBMS

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Physical data model cont.

• Rules for Relationships:


• One-to-one
The primary key of one entity is stored in the
second entity as foreign key

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Physical data model cont.

• Rules for Relationships:


• One-to-many
• The parent relation is the one at the “cardinality 1” side and child is the one on the
“many” side
• Primary key of the parent will be foreign key of the child (for weak relationship)
• Primary key of the parent inherit by the child, and also the Foreign key of the child
(strong relationship)

Weak relationship Strong relationship

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Physical data model cont.

• Rules for Relationships:


• Many-to-many
• Can be implemented by introducing a new intermediate tables
• The foreign key of the new tables consist of the Primary Key of the original two relation
• The primary key of the new tables can be composed from primary key of the original two
tables, or create new primary key for the intermediate table

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Example
Logical

Physical

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Relational Data Modeling

• Relational data model was first proposed by Ted Codd in 1970


• The relational data model is employed for storing and processing
the data in the database
• Relational data model express the database as a set of relations
(table of values)

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Terminologies

• The database is a set of related relations


• Relations == Tables
• Each relation has a name which indicate what type of tuples the
relation has
• Each relation has
• Columns == Attributes
• Rows == Tuples
• A tuple in a relation is a real-world entity
• Each data value in a tuple is called field

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Terminologies

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Characteristics of relations

• Each relation in database must have a distinct or unique name


• A relation must not have two attributes with the same name
• Duplicate tuples must not be presented in a relation

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Characteristics of relations cont.

• Each tuple must have exactly one data value for an attribute
(multivalued attributes are not allowed)
• NULL value in the tuple is used when the value is not available

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Characteristics of relations cont.

• Tuples in a relation do not have to follow a significant order (not


order-sensitive)
• The attributes also do not have to follow certain ordering

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Relational Model Constraints

• Inherent Model-Based Constraints


• The constraints that are implicit in a data model
• Example: a relation in a database must not have duplicate tuples
• Schema-Based Constraints
• Explicit constraint can be seen in a schema of the data model
• Domain constraints, Key constraint and constraint on Null Values, entity
Integrity constraints, Referential integrity constraints
• Application-Based Constraints
• Constraints that cannot be applied in database schema
• Expressed in application programs

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Relational Model Constraints cont.

• Domain constraints
• Each attribute in a tuple is declared to be of a particular domain
• Key constraint and constraint on NULL values
• A key can either be a single attribute or a subgroup of attributes that can
recognize a particular tuple in a relation
• The constraint on NULL values defines whether an attribute is allowed to
carry Null value or not
• Entity Integrity Constraint
• A primary key of a tuple can never be NULL

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Relational Model Constraints cont.

• Referential Integrity Constraint


• The referential integrity constraint holds if the foreign key of relation R1
that refers to the relation R2 satisfies following two conditions:
1. The set of attributes that form foreign key of relation R1 should have the same
domain as the primary key of the referenced relation R2.
2. In the current state, the set of values of the foreign key in tuple t1 of relation R1
must match a primary key value in referenced relation R2 or it could be NULL.

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Relational Schema

• Relational Schema:
• A blueprint used in database design to represent the data to be entered
into the database and describe how that data is structured in relations

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Converting ERD to Relational Schema

• Converting entity set into relational schema


• Entity is mapped as relation in relational schema
• Attributes of entity set are mapped as attributes for that relations
• Primary Key of entity becomes Primary key for that relation

COURSE(CRS_CODE, DEPT_CODE, CRS_DESCRIPTION, CRS_CREDIT)

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Converting ERD to Relational Schema

• Converting entity set with multivalued attribute


• Applying multivalued attribute can lead to data redundancy
• Separate relation is created for multivalued attribute
• Key attribute and multivalued attribute of entity set becomes primary key of
relation.
• Separate relation is created with remaining attributes.

STUDENT(STUDENT_ID, STUDENT_NAME)
STUDENT_PHONE(STUDENT_ID, STUDENT_PHONE)

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Converting ERD to Relational Schema

• Converting entity set with composite attribute


• The composite attribute should not be include
• Instead use all part of the composite attribute as simple attribute

STUDENT(STUDENT_ID, STUDENT_LNAME_STUDENT_FNAME)
STUDENT_PHONE(STUDENT_ID, STUDENT_PHONE)

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Converting ERD to Relational Schema

• Converting one-to-one relationship


• Separate relation are created for all participating entity set
• Key attribute of one entity become foreign attribute for another entity

Customers(idCustomer, name)
Adresses(idAdresses, Address, idCustomer)

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Converting ERD to Relational Schema

• Converting one-to-many relationship

COURSE(CRS_CODE, DEPT_CODE, CRS_DESCRIPTION, CRS_CREDIT)


CLASS(CLASS_CODE, CRS_CODE, CLASS_SECTION, CLASS_TIME, ROOM_CODE, PROF_NUM)

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Converting ERD to Relational Schema

• Converting many-to-many relationship

Students (StudentID, StudentName, Age)


Class (ClassID, ClassName)
Enrollment (EnrollmentID, StudentID, ClassID)
INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia
www.its.ac.id
Assignment 1

• In a group of 3-4
• Choose an application (can be any application)
• Suppose you are a database designer who will create a similar application
1. Identify, what entities are needed to build the application
2. Identify, the relationship that connects between entities
3. Identify the cardinality of each relationship
4. Identify the attribute that at least be owned by each entity
5. Create a conceptual, logical, and physical (mySQL as DBMS) ERD
6. Create a relational schema

INSTITUT TEKNOLOGI SEPULUH NOPEMBER, Surabaya - Indonesia


www.its.ac.id
Thank you

You might also like