0% found this document useful (0 votes)
9 views

Chp2 Data Models

Uploaded by

A R P A N z
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Chp2 Data Models

Uploaded by

A R P A N z
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 55

CHAPTER 2 :DATA MODELS

Presented by : Er. Lali Manandhar


Assistant Senior Lecturer
Everest Engineering College
Data Models
⮚Data Model is link between user’s view of the world and bits
stored in computer.
⮚It define the structure of a database, and certain constraints that
the database should obey
⮚It is the fundamental entities to introduce abstraction in a DBMS.
⮚It defines how data is connected to each other and how they are
processed and stored inside the system.
Conceptual Data Model
Entities : Time
Product
Sales
Store

🞂 It is highly abstract i.e. we don't have much details.

🞂 It can be understood easily by both technical and non technical user.

🞂 It can be easily enhanced. (Note : From above diagram , entities Time, Product
and Store have direct relationship with Sales entity, due to which lot of
information can be obtained by looking at the conceptual data model. And since
it is not a digital document , it can be easily enhanced.)

🞂 Only 'entities' are visible.


Continue…
⮚Data model describes possible schemas & it comprise three
parts:
1. Structural part : Consist of a set of rules according to which
databases can be constructed.
2. Manipulative part : Defining the type of operation that are
allowed on the data
3. A set of integrity constraints : Which ensures that the data is
accurate
Stages of data models
🞂 Stages of data models are :
1. Conceptual Data Model
2. Logical Data Model
3. Physical Data Model
Conceptual Data Model

🞂 Relationship among entities are abstract too. (That is even relationship details
are hidden)
🞂 Not any software tools are required to define data models. (Since , conceptual
data models can be written on a piece of paper or white board, there is not any
requirement of software tools)
Logical Data Model
Logical Data Model
🞂 Attributes of each entity are present, which are further identified as keyed and non-
keyed attributes.

🞂 Keyed attributes define uniqueness of entity.

🞂 All the keyed attributes are placed above line as shown in figure above and all non-
keyed attributes are placed below line.

🞂 Primary key - foreign key relationship are clearly defined in logical data model. In
above example Date, Product ID, Store ID are primary key for Time, Product and
Store entity respectively, and can also be foreign key for Sales entity.

🞂 User friendly attributes are present i.e. it becomes easier for both technical and non-
technical user to understand.

🞂 It provides more detailed information as compared to conceptual data model.

🞂 It does not depend on any specific database means you can take this logical model and
implement on any database software i.e. ORACLE, SQLSERVER etc.
Physical Data Model
Physical Data Model
🞂 In this model, entities referred to as tables and attributes are
referred to as columns.
🞂 It provides database compatible table name and database
specific data types.
🞂 Provide concepts that describe detail of how details stored in
the computer, representing information such as record
structures, record orderings, and access paths.
🞂 It is difficult for user to understand
🞂 It requires more effort to be enhanced in comparison to logical
data model.
🞂 It includes indexes, constraints, triggers and other DB objects.
🞂 It is difficult to port to a different databases once design is
finalized.
ER Model
🞂 A database can be modeled as a collection of entities &
relationship among entities.
🞂 An entity is an object that exists and is distinguishable from
other objects. Example: specific person, company, event, plant
🞂 Entities have attributes; Example: people have names and
addresses
🞂 In this database model, relationships are created by dividing
object of interest into entity and its characteristics into
attributes.
🞂 Different entities are related using relationships.
🞂 E-R Models are defined to represent the relationships into
pictorial form to make it easier for different stakeholders to
understand
ER Model
🞂 This model is good to design a database, which can then
be turned into tables in relational model(explained
below).
🞂 While formulating real world scenario into the database
model, ER model creates entity set, relationship set,
general attributes and constraints.
🞂 An Entity–relationship model (ER model) describes the
structure of a database with the help of a diagram,
which is known as Entity Relationship Diagram (ER
Diagram).
🞂 An ER model is a design or blueprint of a database that
can later be implemented as a database.
ER Model
🞂 The main components of E-R model are: entity set and relationship set
🞂 In the following diagram we have two entities Student and College and their
relationship.
🞂 The relationship between Student and College is many to one as a college can
have many students however a student cannot study in multiple colleges at
the same time.
🞂 Student entity has attributes such as Stu_Id, Stu_Name & Stu_Addr and
College entity has attributes such as Col_ID, Col_Name
Entity & Entity Set
🞂 An entity is a "thing" or "object" in the real world that is distinguished
from all other objects.

🞂 An entity is represented as rectangle in an ER diagram.

🞂 An Entity may be an object with a physical existence – a particular person,


car, house, or employee – or it may be an object with a conceptual
existence – a company, a job, or a university course.

🞂 An entity has a set of properties, and the values for some set of properties
may uniquely identify an entity.

🞂 For example, a person may have person_id property whose value uniquely
identifies that person. Thus, the value 677-89-9011 for person_id would
uniquely identify one particular person in the university.
Continued…
🞂 An entity set is a set of entities of the same type that share the same properties, or
attributes.

🞂 All entity set has a key

🞂 The set of all people who are instructors at a given university, for example, can be
defined as the entity set instructor

🞂 Similarly, the entity set student might represent the set of all students in the
university

🞂 Entity sets do not need to be disjoint. For example, it is possible to define the entity
set of all people in a university (person)

🞂 A person entity may be an instructor entity, a student entity, both, or neither. An


entity is represented by the set of attributes.

🞂 Attributes are descriptive properties possessed by each member of an entity set.


Continued…
🞂 The designation of an attribute for an entity set expresses that the database
stores similar information concerning each entity in the entity set; however,
each entity may have its own value for each attribute.

🞂 Possible attributes for student entity set may be ID, name, roll, stream. In
real life , there would be further attributes, such as address, age etc.

🞂 For example, in addition to keeping track of instructors and students, the


university also has information about courses, which are represented by the
entity set course with attributes course_id, title, dept_name and credits. In a
real setting, a university database may keep dozens of entity sets.
Strong And Weak Entity
Strong Entity
🞂 The Strong Entity is the one whose existence does not depend on the existence of
any other entity in a schema.

🞂 It is denoted by a single rectangle.

🞂 A strong entity always has the primary key in the set of attributes that describes the
strong entity.

🞂 It indicates that each entity in a strong entity set can be uniquely identified.

🞂 Set of similar types of strong entities together forms the Strong Entity Set.

🞂 A strong entity holds the relationship with the weak entity via an Identifying
Relationship, which is denoted by double diamond in the ER diagram.

🞂 On the other hands, the relationship between two strong entities is denoted by a
single diamond and it is simply called as a relationship.
Continued…
Weak Entity
🞂 A Weak entity is the one that depends on its owner entity i.e. a strong entity for
its existence.

🞂 A weak entity is denoted by the double rectangle.

🞂 Weak entity do not have the primary key instead it has a partial key that uniquely
discriminates the weak entities.

🞂 The primary key of a weak entity is a composite key formed from the primary
key of the strong entity and partial key of the weak entity.

🞂 The collection of similar weak entities is called Weak Entity Set.

🞂 The relationship between a weak entity and a strong entity is always denoted
with an Identifying Relationship i.e. double diamond.
Continued…
🞂 Let us understand this concept with the help of an example; a customer borrows
a loan. Here we have two entities first a customer entity, and second a loan entity
Relationship & Relationship Set
Relationship
🞂 Relationship is an association among several entities.
🞂 A relationship set is a set of relationships of same type.
🞂 For example, If we define a relationship advisor that associates instructor
Suresh with student Shankar, this relationship specifies that Suresh is an
advisor to student Shankar
Continued…
🞂 A relationship set is a set of relationships of same type. It is a mathematical relation
of n>=2 (possibly non distinct) entity sets. If E1, E2, E3,...., En are entity sets, then
a relationship set R is a subset of
{(e1, e2, e3, ..., en) | e1 ∈ E1, e2 ∈ E2, ...., en ∈ En} Where (e1, e2, e3, ..., en) is a
relationship.
issue table

🞂 Here from table it is clear that , we have alike relationships, that is, (1 , B3), (2 ,
B6), (3 , B1) and (4 , B5) are 4 alike relationship and these relationships form
relationship set.
🞂 If we have descriptive attributes like access_date in a relationship. Descriptive
properties means access date can't be kept in Student or Book schema.
Degree of a relationship set
🞂 The number of different entity sets participating in a relationship set is called as
degree of a relationship set.

1. Unary Relationship
🞂 When there is only ONE entity set participating in a relation, the relationship is
called as unary relationship. For example, one person is married to only one
person

girl

2. Binary Relationship
🞂 When there are TWO entities set participating in a relation, the relationship is
called as binary relationship. For example, Student is enrolled in Course.
Continued…
Binary Relationship

3. n-ary Relationship When there are n entities set participating in a relation, the
relationship is called as n-ary relationship.
Constraints in Data Models

🞂 An ER enterprise schema may define certain constraints


to which the contents of a database must confirm. We
have mapping cardinalities and participation
cardinalities.

🞂 Mapping Cardinalities: Mapping Cardinalities, or


cardinality ratios express the number of entities to
which another entity can be associated via a relationship
set. Or, the number of times an entity of an entity set
participates in a relationship set is known as cardinality.
Continued…
For Binary relationship set R between entity sets A and B, the mapping cardinality
must be of the following :
🞂 One-to-one: An entity in A is associated with at most one entity in B, and an
entity in B is associated with at most one entity in A.

🞂 For example, a person has only one passport and a passport is given to one
person.
Continued…
One-to-many
🞂 An entity in A is associated with any number (zero or more) of entities in B. An
entity in B, however, can be associated with at most one entity in A.

🞂 For example – a customer can place many orders but a order cannot be placed by
many customers.
Continued…
Many-to-one
🞂 An entity in A is associated with at most one entity in B. An entity in B,
however, can be associated with any number (zero or more) of entities in A.

🞂 For example – many students can study in a single college but a student cannot
study in many colleges at the same time.
Continued…
Many-to-many
🞂 An entity in A is associated with any number (zero or more) of entities in B, and
an entity in B is associated with any number (zero or more) of entities in A.

🞂 For example, a student can be assigned to many projects and a project can be
assigned to many students.
Continued…
Participation Constraints
Participation Constraint is applied on the entity participating in the relationship set.
1. Total Participation – Each entity in the entity set must participate in the
relationship. That is, the participation of an entity set E in a relationship set R is
said to be total if every entity in E participates in at least one relationship in R. If
each student must enroll in a course, the participation of student will be total.
Total participation is shown by double line in ER diagram.

2. Partial Participation – The entity in the entity set may or may NOT participate
in the relationship. That is, if only some entities in E participates in relationships
in R, the participation of entity set E in relationship R is said to be partial. If
some courses are not enrolled by any of the student, the participation of course
will be partial.
Continued…
🞂 For example, A company may store the information of dependants (Parents,
Children, Spouse) of an Employee.
🞂 But the dependents don’t have existence without the employee.

🞂 So Dependent will be weak entity type and Employee will be Identifying Entity
type for Dependant.

🞂 A weak entity type is represented by a double rectangle.

🞂 The participation of weak entity type is always total.

🞂 The relationship between weak entity type and its identifying strong entity type
is called identifying relationship and it is represented by double diamond.
Attributes And Keys
Attribute(s)
🞂 Attributes are the properties which define the entity type.
🞂 For example, Roll_No, Name, DOB, Age, Address, Mobile_No are the attributes
which defines entity type Student. In ER diagram, attribute is represented by an
oval.

1. Key Attribute
🞂 The attribute which uniquely identifies each entity in the entity set is called key
attribute.
🞂 For example: Roll_No will be unique for each student. In ER diagram, key
attribute is represented by an oval with underlying lines.
Continued…
2.Composite Attribute
🞂 An attribute composed of many other attribute is called as composite attribute.
🞂 For example, Address attribute of student Entity type consists of Street, City,
State, and Country.
🞂 In ER diagram, composite attribute is represented by an oval comprising of
ovals.
Continued…
3. Multivalued Attribute
🞂 An attribute consisting more than one value for a given entity.
🞂 For example, Phone_No (can be more than one for a given student).
🞂 In ER diagram, multivalued attribute is represented by double oval.

4. Derived Attribute
🞂 An attribute which can be derived from other attributes of the entity type is
known as derived attribute. e.g.; Age (can be derived from DOB). In ER
diagram, derived attribute is represented by dashed oval.
Continued…
The complete entity type Student with its attributes can be represented as:
Continued…
Database Keys
🞂 Keys are very important part of Relational database model. They are used to
establish and identify relationships between tables and also to uniquely identify
any record or row of data inside a table.
🞂 A Key can be a single attribute or a group of attributes, where the combination
may act as a key
Why we need a Key?
🞂 In real world applications, number of tables required for storing the data
is huge, and the different tables are related to each other as well.
🞂 Also, tables store a lot of data in them. Tables generally extends to
thousands of records stored in them, unsorted and unorganised.
🞂 Now to fetch any particular record from such dataset, you will have to
apply some conditions, but what if there is duplicate data present and
every time you try to fetch some data by applying certain condition, you
get the wrong data. How many trials before you get the right data?
🞂 To avoid all this, Keys are defined to easily identify any row of data in
a table.
Continued…
Let's try to understand about all the keys using a simple example

Let's take a simple Student table, with fields student_id, name, phone and age.
🞂 Super Key
Continued…
Super Key
🞂 It is defined as a set of attributes within a table that can uniquely identify each
record within a table. Super Key is a superset of Candidate key.

🞂 In the table defined above super key would include student_id, name, phone etc.

🞂 Confused? The first one is pretty simple as student_id is unique for every row of
data, hence it can be used to identity each row uniquely.

🞂 Next comes, (student_id, name), now name of two students can be same, but
their student_id can't be same hence this combination can also be a key.

🞂 Similarly, phone number for every student will be unique, hence again, phone
can also be a key.

🞂 So they all are super keys.


Continued…
Candidate Key
🞂 Candidate keys are defined as the minimal set of fields which can uniquely
identify each record in a table.

🞂 It is an attribute or a set of attributes that can act as a Primary Key for a table to
uniquely identify each record in that table.

🞂 There can be more than one candidate key.

🞂 In our example, student_id and phone both are candidate keys for table Student.
◦ A candiate key can never be NULL or empty. And its value should be unique.
◦ There can be more than one candidate keys for a table.
◦ A candidate key can be a combination of more than one columns(attributes).
Continued…
Primary Key
🞂 Primary key is a candidate key that is most appropriate to become the main key
for any table. It is a key that can uniquely identify each record in a table

🞂 For the table Student we can make the student_id column as the primary key
Continued…
Composite Key
🞂 Key that consists of two or more attributes that uniquely identify any record in a
table is called Composite key. But the attributes which together form the
Composite key are not a key independently or individually.

🞂 In the above picture we have a Score table which stores the marks scored by a
student in a particular subject.
🞂 In this table student_id and subject_id together will form the composite key.
Continued…
🞂 Secondary or Alternative key : The candidate key which are not selected as
primary key are known as secondary keys or alternative keys.
Student(stud_id)
🞂 Student(roll)

🞂 Student(phone)

🞂 Student(stud_id,roll)

🞂 Student (roll, phone)

🞂 Non-key Attributes : Non-key attributes are the attributes or fields of a table,


other than candidate key attributes/fields in a table.
🞂 Student (stud_id) roll, phone, age, address, section

🞂 Non-prime Attributes : Non-prime Attributes are attributes other than Primary


Key attribute(s)..
Entity-Relationship Diagram
ER Diagram
🞂 It is a visual representation of data that describes how data is related to each
other. In ER Model, we disintegrate data into entities, attributes and setup
relationships between entities, all this can be represented visually using the ER
diagram.
Components of ER Diagram
🞂 Entity, Attributes, Relationships etc form the components of ER Diagram and
there are defined symbols and shapes to represent each one of them.
ER Diagram
Symbols used for ER diagram
Question
🞂 Country Bus Company: A Country Bus Company owns a number of busses.
Each bus is allocated to a particular route, although some routes may have
several busses. Each route passes through a number of towns. One or more
drivers are allocated to each stage of a route, which corresponds to a journey
through some or all of the towns on a route. Some of the towns have a garage
where busses are kept and each of the busses are identified by the registration
number and can carry different numbers of passengers, since the vehicles vary
in size and can be single or double-decked. Each route is identified by a route
number and information is available on the average number of passengers
carried per day for each route. Drivers have an employee number, name,
address, and sometimes a telephone number.
Entities
🞂 Bus - Company owns busses and will hold information about them.
🞂 Route - Buses travel on routes and will need described.
🞂 Town - Buses pass through towns and need to know about them
🞂 Driver - Company employs drivers, personnel will hold their data.
🞂 Stage - Routes are made up of stages
🞂 Garage - Garage houses buses, and need to know where they are.
ER Diagram
ER-Diagram
Continued…
Relationships
🞂 A bus is allocated to a route and a route may have several buses.
🞂 Bus-route (m:1) is serviced by
🞂 A route comprises of one or more stages.
🞂 route-stage (1:m) comprises
🞂 One or more drivers are allocated to each stage.
🞂 driver-stage (m:1) is allocated
🞂 A stage passes through some or all of the towns on a route.
🞂 stage-town (m:n) passes-through
🞂 A route passes through some or all of the towns
🞂 route-town (m:n) passes-through
🞂 Some of the towns have a garage
🞂 garage-town (1:1) is situated
🞂 A garage keeps buses and each bus has one `home' garage
🞂 garage-bus (1:m) is garaged
Question
🞂 Question 1 : Suppose you are given the following requirements for a simple
database for the National Hockey League (NHL):
◦ the NHL has many teams,
◦ each team has a name, a city, a coach, a captain, and a set of players,
◦ each player belongs to only one team,
◦ each player has a name, a position (such as left wing or goalie), a skill level,
and a set of injury records,
◦ a team captain is also a player,
◦ a game is played between two teams (referred to as host_team and
guest_team) and has a date (such as May 11th, 1999) and a score (such as 4 to
2). Construct a clean and concise ER diagram for the NHL database.
Entity
Team
Player
Injury record
Continued…
Relationships
Each player belongs to only one team
Player-Team(m:1)

A team captain is also a player


Player-Team(1:1)

Player can have set of injury records


Player-Injury records (1:m)

Attributes
Continued…
ER-Diagram
Alternate Data Model (hierarchical, network, graph)
Record based logical Models
🞂 Like Object based model, they also describe data at the conceptual and view levels.
🞂 These models specify logical structure of database with records, fields and
attributes.

Hierarchical Model
🞂 This database model organizes data into a tree-like-structure, with a single root, to
which all the other data is linked.
🞂 The hierarchy starts from the Root data, and expands like a tree, adding child nodes
to the parent nodes.
🞂 In this model, a child node will only have a single parent node.
🞂 This model efficiently describes many real-world relationships like index of a book,
recipes etc.
🞂 In hierarchical model, data is organized into tree-like structure with one one-to-
many relationship between two different types of data, for example, one department
can have many courses, many professors and of-course many students.
Continued…
Hierarchical Model

Advantages
🞂 Simplicity

🞂 Data security & Data integrity

🞂 Efficiency

Disadvantages
🞂 Implementation complexity

🞂 Lack of structural independence


Continued…
Relational Model
🞂 In this model, data is organized in two-dimensional tables and the relationship is
maintained by storing a common field.

🞂 This model was introduced by E.F Codd in 1970, and since then it has been the
most widely used database model, in-fact, we can say the only database model
used around the world.

🞂 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.

🞂 Hence, tables are also known as relations in relational model.

🞂 How to design tables, normalize them to reduce data redundancy and how to use
Structured Query language to access data from tables.
Continued…
Relational Model

Advantages
🞂 Flexible & efficiency
🞂 Relationship many-to-many
🞂 Table diagram
🞂 Good management
🞂 Less redundancy
🞂 Searching speed in fast

Disadvantages
🞂 very complex
🞂 not user friendly
🞂 less secure
Continued…
Network Model
🞂 Network Model is same as hierarchical model except that it has graph-like structure rather
than a tree-based structure.

🞂 Unlike hierarchical model, this model allows each record to have more than one parent
record.

🞂 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.

🞂 Also, as the data is more related, hence accessing the data is also easier and fast.

🞂 This database model was used to map many-to-many data relationships.

🞂 This was the most widely used database model, before Relational Model was introduced.
Continued…
Network Model

You might also like