0% found this document useful (0 votes)
22 views46 pages

Chapter 2

Uploaded by

clausn11223
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views46 pages

Chapter 2

Uploaded by

clausn11223
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 46

Chapter 2

Data Models

Prepared By:
Ms. Ayushi Gondaliya
Assistant Prof.
SRCOE, RAJKOT
Data Models
 Data Models
◦ Data Model is the modeling of the data
description, data semantics, and consistency
constraints of the data.
◦ It provides the conceptual tools for describing
the design of a database at each level of data
abstraction.
Data model Schema and Instance

 The data which is stored in the database at a


particular moment of time is called an instance of
the database.
 The overall design of a database is called schema.
 A database schema is the skeleton structure of
the database. It represents the logical view of the
entire database.
 A database schema is designed by the database
designers to help programmers whose software
will interact with the database. The process of
database creation is called data modeling.
E-R Model(Entity-Relationship)
 ER model stands for an Entity-Relationship
model. It is a high-level data model. This
model is used to define the data elements
and relationship for a specified system.
 It develops a conceptual design for the
database. It also develops a very simple and
easy to design view of data.
 In ER modeling, the database structure is
portrayed as a diagram called an entity-
relationship diagram.
Component of ER Diagram
 1. Entity:
◦ An entity may be any object, class, person or
place.
◦ In the ER diagram, an entity can be
represented as rectangles.
◦ Consider an organization as an example-
manager, product, employee, department etc.
can be taken as an entity.
a. Weak Entity:
◦ An entity that depends on another entity
called a weak entity.
◦ The weak entity doesn't contain any key
attribute of its own.
◦ The weak entity is represented by a double
rectangle.
 2. Attribute
◦ The attribute is used to describe the property
of an entity.
◦ Eclipse is used to represent an attribute.
◦ For example, id, age, contact number, name,
etc. can be attributes of a student.
a. Key Attribute
◦ The key attribute is used to represent the
main characteristics of an entity.
◦ It represents a primary key.
◦ The key attribute is represented by an ellipse
with the text underlined.
b. Composite Attribute
◦ An attribute that composed(divided into
subparts) of many other attributes is known
as a composite attribute.
◦ The composite attribute is represented by an
ecllipse, and those ellipses are connected with
an ellipse.
c. Multivalued Attribute
◦ An attribute can have more than one value.
◦ The double oval is used to represent
multivalued attribute.
◦ For example, a student can have more than
one phone number.
d. Derived Attribute
◦ An attribute that can be derived from other
attribute is known as a derived attribute.
◦ It can be represented by a dashed ellipse.
◦ For example, A person's age changes over
time and can be derived from another
attribute like Date of birth.
 3. Relationship
◦ A relationship is used to describe the relation
between entities.
◦ Relationship is an association between
entities.
◦ Diamond or rhombus is used to represent
the relationship.
 a. One-to-One Relationship
◦ When only one instance of an entity is
associated with the relationship, then it is
known as one to one relationship.
◦ For example, A female can marry to one
male, and a male can marry to one female.
 b. One-to-many relationship
◦ When only one instance of the entity on the
left, and more than one instance of an entity
on the right associates with the relationship
then this is known as a one-to-many
relationship.
◦ For example, Scientist can invent many
inventions, but the invention is done by the
only specific scientist.
 c. Many-to-one relationship
◦ When more than one instance of the entity
on the left, and only one instance of an entity
on the right associates with the relationship
then it is known as a many-to-one
relationship.
◦ For example, Student enrolls for only one
course, but a course can have many students.
 d. Many-to-many relationship
◦ When more than one instance of the entity
on the left, and more than one instance of an
entity on the right associates with the
relationship then it is known as a many-to-
many relationship.
◦ For example, Employee can assign by many
projects and project can have many
employees.
Practice….
 Draw an E-R diagram for Banking system
 Draw an E-R diagram for online shopping
system
Role
 Roles are indicated by labeling the lines
that connect relationship(diamond) to
entity(rectangles).
 Role labels are optional it is only use for
clarify meaning of relationships.
 Example:
Super class
A super class is an entity from which
another entity can be derived.
 E.g. Account entity has two sub entity
saving-account and current-account.
 So, here Account is called super class.
Account
Super class

Saving-account Current-account
Sub Class
 A sub class is an entity that is derived
from another entity.
 E.g. saving-account and current-account is
derived from entity account.
 So, saving-account and current-account
are sub class.
Account Sub Class

Current-account Saving-account
Generalization
 Generalization is like a bottom-up approach in which
two or more entities of lower level combine to form
a higher level entity if they have some attributes in
common.
 For example, Faculty and Student entities can be
generalized and create a higher level entity Person.
Specialization
 Specialization is a top-down approach, and it is opposite to
Generalization. In specialization, one higher level entity can
be broken down into two lower level entities.
 For example: In an Employee management system,
EMPLOYEE entity can be specialized as TESTER or
DEVELOPER based on what role they play in the company.
Generalization
Specialization
Aggregation
 Aggregation is a process in which a
single entity alone is not able to make
sense in a relationship so the relationship
of two entities acts as one entity.
 Process of creating an entity by combining
various components of E-R diagram is
called aggregation
Data Models
 Data Model is the modeling of the data
description, data semantics, and
consistency constraints of the data.
 It provides the conceptual tools for
describing the design of a database at
each level of data abstraction.
 The most famous example of database
model is the relational model, which uses
a table-format.
Types of database models:
 Hierarchical Model
 Network Model
 E-R Model
 Relational model
 Object Oriented database Model
Hierarchical Model
 A hierarchical model represents the data in a tree-
like structure in which there is a single parent for
each record.
 The hierarchy starts from the Root data, and
expands like a tree, adding child nodes to the
parent nodes.
 In hierarchical model, data is organized into tree-
like structure with one-to-many relationship
between two different types of data.
 for example shown in fig., one department can have
many courses, many professors and of-course many
students.
Hierarchical Model
Network Model
 This is an extension of the Hierarchical model.
 In this model data is organized more like a
graph, and are allowed to have more than one
parent node.
 In this database model data is more related as
more relationships are established in this
database model.
 This database model was used to map many-to-
many data relationships.
Network Model
E-R Model
 In this database model, relationships are created by
dividing object of interest into entity and its
characteristics into attributes.
 This model is good to design a database, which can
then be turned into tables in relational model.
 example, If we have to design a School Database,
then…
◦ Student will be an entity with attributes name, age,
address etc. As Address is generally complex, it can be
another entity with attributes street name, pincode, city
etc, and there will be a relationship between them.
E-R Model
Relational Model
 The basic structure of data in the relational
model is tables. All the information related to a
particular type is stored in rows of that table.
 In this model, data is organized in two-
dimensional tables and the relationship is
maintained by storing a common field.
 Hence, tables are also known as relations in
relational model.
Relational Model
S_id Name age Sub_id name teacher
1 Abc 20 1 Dbms ASG
2 Cde 21 2 Ds MRP

3 Def 21 3 Java JKR

4 Efg 21 4 .net MNT

S_id Sub_id marks


1 2 95
2 2 85
2 3 45
3 4 75
Object Oriented Model
 This data model is another method of
representing real world objects.
 It considers each object in the world as objects
and isolates it from each other.
 It groups its related functionalities together and
allows inheriting its functionality to other
related sub-groups.
Integrity Constraints
 Integrity constraints are a set of rules. It is used
to maintain the quality of information.
 Integrity constraints ensure that the data
insertion, updating, and other processes have to
be performed in such a way that data integrity
is not affected.
 Thus, integrity constraint is used to guard
against accidental damage to the database.
Types Of Constraints
 Not null
 Check
 Unique
 Primary key
 Foreign key
 Not null
◦ By default, a column can hold NULL values.
◦ The NOT NULL constraint enforces a column to
NOT accept NULL values.
◦ This enforces a field to always contain a value, which
means that you cannot insert a new record, or update
a record without adding a value to this field.
◦ Foe e.g. stu_id, stu_name can not be null.
 Check
◦ The CHECK constraint is used to limit the
value range that can be placed in a column.
◦ The constraint can be applied for a single
column or a multiple columns.
◦ e.g. Values of SPI should be between 0 to 10.
 Unique
◦ The UNIQUE constraint ensures that all
values in a column are different.
◦ However, you can have many UNIQUE
constraints per table.
◦ A column can have null value but the values
can’t be duplicated.
◦ E.g. stu_id, enrollment no should have
different values.
 Primary key
◦ The PRIMARY KEY constraint uniquely
identifies each record in a table.
◦ Primary keys must contain UNIQUE values,
and cannot contain NULL values.
◦ A table can have only ONE primary key.
◦ Primary key = unique key + not null
◦ Eg. Enrollment no column should have unique
value and it can’t be null.
 Foreign key
◦ A FOREIGN KEY is a key used to link two tables
together.
◦ A FOREIGN KEY is a field (or collection of fields) in
one table that refers to the PRIMARY KEY in another
table.

Foreign key
P_id P_name P_age Ordr_id Ordr_no P_id

1 Abc 17 1 1234 2

2 def 22 2 4567 1

Person Order
Thank You

You might also like