HND Database 2
HND Database 2
Types of Attributes
Simple attribute
Simple attributes are atomic values, which cannot be divided further. For example, a student's phone number
is an atomic value of 10 digits.
Composite attribute
Composite attributes are made of more than one simple attribute. For example, a student's complete name
may have first_name and last_name.
ER Model Basics
Types of Attributes
Derived attribute
Derived attributes are the attributes that do not exist in the physical database,
but their values are derived from other attributes present in the database. For
example, average_salary in a department should not be saved directly in the
database, instead it can be derived. For another example, age can be derived
from data_of_birth.
Single-value attribute
Multi-value attribute
Multi-value attributes may contain more than one values. For example,
a person can have more than one phone number, email_address, etc.
Types of cardinalities:
- One-to-one
- One-to-Many
- Many-to-One
- Many-to-Many
ER Model Basics
Types of cardinalities:
One-to-one
One-to-many
Many-to-one
Many-to-many
The requirements will tell you two things from a database perspective, what are
the entities we need to gather and store information above and what
associations (relationships) exist between these entities.
To identify entities, read the requirements and user stories and pick all nouns.
To identify relationships, read the requirements and user stories and pick all the
verbs.
After making a list of nouns and verbs, for each noun ask yourself how relevant
it is to keep track of that noun to the owners of the database. What kind of
information needs to be tracked per noun?
ER Diagram Representation
Once these lists are clear, the next step would be to start drawing the
ER diagram, you can use any tool but the shapes and symbols remain
the same.
One-to-many
Many-to-one
Many-to-many
Total Participation
Partial participation
• The table name and column names are helpful to interpret the
meaning of values in each row. The data are represented as a
set of relations. In the relational model, data are stored as
tables. However, the physical storage of the data is
independent of the way the data are logically organized.
Relational Model Concepts
Tables
• In relational data model, relations are saved in the format of Tables.
This format stores the relation among entities. A table has rows and
columns, where rows represents records and columns represent the
attributes.
Tuple
• A single row of a table, which contains a single record for that
relation is called a tuple.
Relation instance
• A finite set of tuples in the relational database system represents
relation instance. Relation instances do not have duplicate tuples.
Relational Model Concepts
Relation schema
• A relation schema describes the relation name (table
name), attributes, and their names.
Relation key
• Each row has one or more attributes, known as
relation key, which can identify the row in the relation
(table) uniquely.
Attribute domain
• Every attribute has some pre-defined value scope,
known as attribute domain.
Relational Model Concepts
Constraints
- Key constraints
- Domain constraints
- Referential integrity constraints
Relational Model Concepts
Constraints
Key Constraints
There must be at least one minimal subset of attributes in the relation, which can identify a
tuple uniquely. This minimal subset of attributes is called key for that relation. If there are more
than one such minimal subsets, these are called candidate keys.
- In a relation with a key attribute, no two tuples can have identical values for key attributes.
- A key attribute can not have NULL values.
Key constraints are also referred to as Entity Constraints.
Relational Model Concepts
Constraints
Domain Constraints
There are several processes and algorithms available to convert ER Diagrams into Relational
Schema. Some of them are automated and some of them are manual. We may focus here on
the mapping diagram contents to relational basics.
Mapping Process
Mapping Process
MINI PROJECT 2
Project Description
Database model for Taxi Booking Application
• Part 1: Develop ER Model for Taxi Booking App
• Part 2: Convert the ER Model into a Relational
model explaining each step
• Part 3: Implement the model on MySQL
Workbench
• Part 4: Document your solutions on Microsoft
word, create a pdf file and submit.
Summary
So far, we have looked at the following:
• General Architecture
• Data Models
• Entity Relationship Model
• Relational Model
• Converting an ER to a Relational Model
• Assignment
• Mini Project 2: Do database modeling for a Taxi Booking
Application
Congratulations!