You are on page 1of 46

CHAPTER 3

DATABASE MODELING
 The first step in database design is requirements
collection and analysis.
 The next step is conceptual data modeling
DATABASE  It provides concepts that are close to the way
many user perceive the data.
MODELING  It identifies the business objects that would
exist in the system and relationships among
them.
 E-R is used to conceptual database design.
DATABASE MODELING

Logical design:-
It’s the actual implementation of the database, using a DBMS such as SQL.
So the conceptual schema is transformed from the high-level data model into the
implementation data model.
The last step is the physical design phase
Internal storage structures file organizations, indexes, access paths, and physical
design parameters for the database files are specified.
In parallel with these activities, application programs are designed and
implemented.
• Entity: Entity refers to an\object "or \ thing “ in real world with the
existence that can be differentiated from other objects.
• Object may be any person, place, event etc. An entity can be an object
with physical existence like student, a car, employee ,etc. or an object
with conceptual existence like job, positioned,
• Attributes: An attribute is particular properties that describe an entity.

Basic
For example,
• A student can be described by his name, age, address, height, class

concepts
etc.
• Loans can be described by their types such as house loan, car loan etc.
• Employees in any company can be described by their Employee_ID,
name, department, designation etc. A car can be described by its color,
model ,company etc.
• An Attribute is named Column of a relation
presented.
• In the relational model, relations are used to hold
information about the objects to be presented in
the database.
• A relation is represented a two dimensional table
…Attributes in which the rows of the table correspond to
individual records and the table columns
correspond to attributes.
• Attributes can appear in any order and the
relation will still be the same relation, and
therefore convey the same meaning.
Domain: A domain is the set of allowable values for one or
more attributes.

For example, a domain of month-of-year can accept January,


February….December as possible values, a domain of integers
can accept whole numbers that are negative, positive and zero.
…Attributes
Every attribute in a relation is defined on a domain.

Value is the information or data which is stored in attributes of


any entity.
• Strong Entity:
 An entity set with key attribute.
 Its existence is not depend on any other
entity
 Re presented by single rectangle
Type of • Weak Entity:
Entity  Do not have key attribute and are
dependent on other entity
 Existence dependent(i.e.it must be
associated with an identifying entity)and its
participations total.
 Represented by double rectangle
Type of Attributes

• Simple and Composite Attributes


• Simple Attributes are those which can not be divided into subparts.
• Example:- Age of student Age=21.
• Composite Attributes are those which can be divided into subparts
• Ex. Name of a student can be divided into First Name, Middle Nam and
Last Name.
• Address can be (E-mail, Phone number, city/country, street and etc.)
Type of Attributes

• Single Valued and Multi-Valued Attributes


• Single Valued Attribute:- An attribute having only single value for a particular entity is known as single value attribute. Ex.
Age of student.
• Multi-Valued Attributes :-An attribute having more than one possible value for a particular entity is known as multi-
valued attribute.
• Ex. Phone number
• Derived Attributes and Stored Attributes
• Derived Attributes :An attribute that can be derived from other known attributes is known as derived attribute.
• Ex. Age of employees can be derived if you know date of birth.
• Stored Attributes:-An attribute which can not be derived by other known attributes is known as stored attribute. Ex. Date
of birth of any employee.
.
Relationships

• Relationships are an
association between two or
more entities.
• Relationships shows how the
Entity are connected or
related to each other.
• Total number of entity sets participate in a
relationship set is known as degree of that
Degree Of relationship set.
• There are three types of relationship that
Relationship exist between Entities:-
1. Binary Relationship
2. Recursive Relationship
3. Ternary Relationship
Degree Of Relationship

Binary Relationship(Involves two entities)

Ternary Relationship(Involves three entities)

Recursive Relationship(One Entity)


Types Of Relations

• There are 3 types of relationships in relational database design.

• They are: One-to-One

• One-to-Many (or Many-to-One)

• Many-to-Many
Cardinality: The cardinality of a relationship is the actual number of related occurrences
for each of the two entities. The basic types of connectivity for relations are: one-to-one,
one-to-many, and many to-many.
One to One

• If one instance of first entity is associated


to exactly one instance of second entity
and one instance of second entity
associated to only one instance of the
first entity.

• Example: Employee with Vehicle


 Husband with Wife
 Student with ID
 Person with Passport
One to Many

• One instance of first entity is


associated to many instance of the
second entity and one instance of
the second entity is associated to
only one instance of the first
entity.
• Example : Mother with Children
• Doctor with Patient
• Instructor with
course
Many to Many

• One instance of first entity is


associated to many instance
of the second entity and one
instance of the second entity
is associated to many
instance of the first entity.
KEYS

A key in a table is a field or group of fields that creates identity, makes


relationship with another table and/or make a table more efficient.

A key is an attribute or set of attributes that is used to identify data in


entity sets.

A DBMS key is an attribute or set of an attribute which helps you to


identify a row(tuple) in a relation(table).
Type of Keys

• There are many keys that are used in


the relation.
1. Super Key
StId StName StDepartment
• A super key is a single attribute or a
set of attributes that can uniquely 001 Ababe BAIS
identify a tuple.
• In student table super keys are (StId, 002 Chala MIS
StName, StDepartment ), (StId, 003 Ababe SWE
StName) ,(StId) etc.
• All combinations can identify data
uniquely.
2. Candidate
Key
• The minimal set of attribute
which can uniquely identify
a tuple is known as
candidate key.
• The value of Candidate Key
is unique and non-null for
every tuple.
• There can be more than one
candidate key in a relation

Alternate Keys: All the candidate keys except Primary Key


3. Primary
Key
• The primary key is an attribute or a set of
attributes that uniquely identify a specific
instance(data) of an entity.
• Every entity in the data model must have a
primary key whose values uniquely identify
instances of the entity.
• A column or group of columns in a table which
helps us to uniquely identifies every row in
that table is called a primary key.
• Any entity set can have more than one
Candidate key but only one Primary Key.
 Two rows can't have the same primary key value
 It must for every row to have a primary key value.
 The primary key field cannot be null.
 The value in a primary key column can never be
modified or updated if any foreign key refers to that
Rules for primary key.

defining
Primary
key
Foreign key

• A Foreign key is a key borrowed from another related table (that’s why its
foreign) in order to make the relationship between two tables.
• A foreign key is an attribute in any entity set which is also a Primary Key in
any other entity set and is used to link two tables together.
• A foreign key is a column which is added to create a relationship with
another table.
• When a primary key from one table appears in another table, it is called a
foreign key.
Foreign key
Student table

Course table
CCode IDNo CTitle CChr
MIS001 001 Database 5
MIS002 003 Networking 5

IDNo is primary key for student table and foreign key for course table
Primary Key and Foreign Key
Entity Integrity

These are the rules or constraints applied to the database to keep data
stable, accurate or consistent.

Entity Integrity ensures that there are no duplicate records within the
table and that the field that identifies each record within the table is
unique and never null.

The existence of the Primary Key is the core of the entity integrity. If you
define a primary key for each entity, they follow the entity integrity rule.
Referential Integrity

Referential integrity is the logical dependency of a foreign key on a


primary key.

The integrity of a row that contains a foreign key depends on the integrity
of the row that it references—the row that contains the matching primary
key.

By default, the database server does not allow you to violate referential
integrity
• The Rule defines that a foreign key have a matching primary
key.
• Reference from a table to another table should be valid.

…Referential
Integrity
…Referential Integrity
• Once requirement are collected and analyzed, database
design stage begins.
• E-R diagrams represents the logical structure of a database.
• E-R modeling is begins by identifying the important data
called entities and relationships between the data that must
Entity be represented in the model.
• Symbols used in E-R diagrams are shown below
Relationship
Diagram(E-
R Diagram)
E-R Diagram Symbols
E-R Diagram
Example of Attributes

Lastname Firstname

ID No.
Gender

Student Address

Birth date

Email
Example of Attributes
Name
Chairperson

Lastname Firstname

Program ID
Enrollment ID No.
Date
Gender

Program enrolls Student Address

ID No. Birth date

Email
has Faculty
Lastname

Firstname

34
E-R Diagram
Identify all the entities in the system. An entity
should appear only once in particular diagram.

Guidelines of
Identify relationship between entities. Connect
them using a line and add a diamond in the
middle describing the relationship.

how to draw
E-R Add attributes for entities.

Identify Cardinality Ratio


E-R Diagram
Enhanced Entity Relationship and Object modeling
Subclass, Super-class and Inheritance
Subclass, Super-class and Inheritance
Subclass, Super-class and Inheritance
Subclass, Super-class and Inheritance
Subclass, Super-class and Inheritance
Specialization and Generalization
Specialization and Generalization
• Generalization is a process by which two or more entity sets can be
combined into a single entity set by determining similarities between
the entities.
THE END!

You might also like