Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
136 views

Unit-2 Data Models

The document discusses entity relationship (ER) modeling and ER diagrams. It defines key concepts in ER modeling including entities, attributes, relationships, entity sets, strong and weak entities, and cardinality constraints. It provides examples and notation for representing these concepts in ER diagrams including symbols for entities, attributes, relationships, and cardinality constraints like one-to-one, one-to-many, and many-to-one relationships. Finally, it demonstrates an example ER diagram for a library system to illustrate how these concepts come together in a conceptual model of entities and their relationships in a database.

Uploaded by

Shiv Patel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
136 views

Unit-2 Data Models

The document discusses entity relationship (ER) modeling and ER diagrams. It defines key concepts in ER modeling including entities, attributes, relationships, entity sets, strong and weak entities, and cardinality constraints. It provides examples and notation for representing these concepts in ER diagrams including symbols for entities, attributes, relationships, and cardinality constraints like one-to-one, one-to-many, and many-to-one relationships. Finally, it demonstrates an example ER diagram for a library system to illustrate how these concepts come together in a conceptual model of entities and their relationships in a database.

Uploaded by

Shiv Patel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 92

Unit

Unit –2
–2
Data Model
Data Model
Entity Relationship model
 In 1976, Chen developed the ER or (Entity
Relational Model)
 It is a high-level conceptual data model that is useful
in developing a conceptual design for a database.
 Entity-Relation model is based on the notion of real-
world entities and the relationship between them.
 ER modeling helps you to analyze data requirements
systematically to produce a well-designed database.
 It develops a conceptual design for the database. It
also develops a very simple and easy to design view of
data.
What is E-R diagram?
 E-R diagram: (Entity-Relationship diagram)
 It is graphical (pictorial) representation of database.
 It uses different types of symbols to represent
different objects of database.
 ER diagram having three main components:
1) Entity
2) Attributes
3) Relationship
Notation used in ER diagram
Entity
 Entity: An entity is a person, a place or an object or
anything in real world with its own independent
existence.
 Represent by Rectangles box.
 Entities of a college database:
• Student Entity Name
• Professor/Faculty
• Courses Symbol

• Department
• Result
• Class
• Subject
Entity Set
 Entity Set: It is a set (group) of entities of same type.
 Examples:
• All persons having an account in a bank
• All the students studying in a college
• All the professors working in a college
• Set of all accounts in a bank
 There are two types of entity set.
(a) Strong entity type
(b) Weak entity type
Strong entity type
 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 its
own 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.
Weak entity type
 A Weak entity is the one that depends on its owner
entity i.e. a strong entity for its existence.
 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.
 A weak entity is denoted by the double rectangle.
Weak entity type
Weak entity type
Weak entity set
 Weak entity set: An entity set that does not have a primary
key is called weak entity set.
Payment-date

loan-no amount payment-no Loan-amount

loan L_P payment

Strong Weak Entity Weak Entity


Entity Set Relationship Set

• Weak entity set is indicated by double rectangle.


• Weak entity relationship set is indicated by double diamond.
Weak entity set
 The existence of a weak entity set depends on the existence of a
strong entity set.
 The discriminator (partial key) of a weak entity set is the set of
attributes that distinguishes all the entities of a weak entity set.
 The primary key of a weak entity set is created by combining
the primary key of the strong entity set on which the weak
entity set is existence dependent and the weak entity set’s
discriminator.
 We underline the discriminator attribute of a weak entity set
with a dashed line.
 Payment entity has payment-no which is discriminator.
 Loan entity has loan-no as primary key.
 So primary key for payment is (loan-no, payment-no).
Strong Entity Set vs Weal Entity Set
Attributes
 Attributes: Attribute is a properties or details about an entity.
 Represent by Ellipses.
 Examples:
• Attributes of Student:
1. Roll No Attribute
Name
2. Student Name
3. Branch Symbol
4. Semester
5. Address
6. Mobile No
7. Age
8. SPI
9. Backlogs
Types of Attributes
Simple Attribute Composite Attribute
cannot be divided into subparts can be divided into subparts
e.g. Salary, Age e.g. Name (first name, middle name,
last name), Address

First Middle Last


Name Name Name

Salary Age Name Address

Student Student
Types of Attributes
Single valued Attribute Multi valued Attribute
has single data value have multiple data value
e.g. Rollno, CPI e.g. Phoneno (person may have multiple
phonenos), EmailID

RollNo CPI PhoneNo EmailID

Student Student
Types of Attributes
Stored Attribute Derived Attribute
It’s value is stored manually in It’s value is derived or calculated from
database other attributes
e.g. Birthdate e.g. Age (can be calculated using
current date and birthdate)

RollNo Birthdate Birthdate Age

Student Student
Key Attributes
 This is an attributes of a entity must have a unique
value by which any row can be identified is called as
key attribute of entity.
 Example: RollNo for student.
Null Attributes
 It does not have a value and can be left blank, it’s
optional can be filled or cannot be.
 This is special attribute the value of which is
unknown, unassigned, not applicable or missing.
 Example: Apartment_number attribute of address
field applies to address in apartment buildings only
and not to other address like row houses. Hence, an
address of a row house would have NULL for its
Apartment_number attribute.
Descriptive Attributes
 Descriptive attributes: Attributes of the relationship is called
descriptive attribute.

Issue
RollNo Name Date BookNo Name

Student Issue Book

Branch Sem Author Price


Relationship
 Relationship: association (connection) between several
entities.
 It should be place between two entities and line connecting it
to entity.
 Symbol is diamond.
Relationship
Name
Symbol/notation used in ER diagram
E-R Diagram of Library System
RollNo Name BookNo Name

Student Issue Book

Branch Sem Author Price

 Each and every entity must have one primary key attribute.
 Relationship between 2 entities is called binary relationship.
Recursive relationship set
 Recursive relationship set: The same entity set participates
in a relationship set more than once then it is called recursive
relationship set.
FacID FName DeptID DName

Faculty Works Department

Post

FName Post DName


Vatsal Professor Prof. Computer
Aakash Professor Civil
Jijeesh Sir HOD Mechanical
Constraints on
Relationship
Mapping Cardinality (Cardinality Constraints)
 It represents the number of entities of another entity
set which are connected to an entity using a
relationship set.
 It is most useful in describing binary relationship sets.
 For a binary relationship set the mapping cardinality
must be one of the following types:
1. One to One
2. One to Many
3. Many to One
4. Many to Many
One-to-One relationship
 An entity in A is associated with at most (only) one entity in B
and an entity in B is associated with at most (only) one entity
in A.
customer borrow loan
A1 B1
C1 L1
A2 B2
C2 L2

Customer Loan C3 L3
A B

 Example: A customer is connected with only one loan using


the relationship borrower and a loan is connected with only
one customer using borrower.
One-to-Many relationship
 An entity in A is associated with more than one entities in B
and an entity in B is associated with at most one (only) entity
in A.

Teacher Teaches Student


A1 B1
T1 S1
A2 B2
T2 S2

Teacher Student T3 S3
A B S4

 Example: In the one-to-many relationship a student is


connected with only teacher using teaches and a teacher is
connected with more than one student using teaches.
Many-to-One relationship
 An entity in A is associated with at most (only) one entity in B
and an entity in B is associated with more than one entities in
A.

Employee Works_for Department


A1 B1
E1 D1
A2 B2
E2 D2

Employee Department E3 D3
A B
E4

 Example: In a many-to-one relationship a Department is


connected with more than one employee using works_for and a
employee is connected with only one department using
works_for.
Many-to-Many relationship
 An entity in A is associated with more than one entities in B
and an entity in B is associated with more than one entities in
A.
Issued
Book By Student
A1 B1
B1 S1
A2 B2
B2 S2

Book Student B3 S3
A B B4 S4

 Example: A Book is connected with more than one student


using issued by and a student is connected with more than one
books using issued by.
Participation constraints
Participation constraints: It specifies the participation of
an entity set in a relationship set.
 There are two types participation constraints
1. Total participation
• Every entity in the entity set participates in at least one
relationship in the relationship set.
• Indicated by Double line
• Example: Every department must have a manager.

Department Manged_by Manager


Participation constraints
2. Partial participation
• In case of partial participation more than one object in
an entity may participate in a relationship.
• Indicated by single line.
• Example: Employees works for department.

Employee Works_for Department


Total participation VS Partial participation

Partial participation Total participation


• some entities in the entity set • every entity in the entity set
may not participate in any participates in at least one
relationship in the relationship in the
relationship set. relationship set.
• indicated by single line • indicated by double line

customer borrow loan

C1 L1

C2 L2

has only saving account C3


Notation used in ER diagram for representing Relations
1. Cardinality ratio notation
• In this method we use cardinality of each entity
involved into the relation.
• 1,M,N specifies on each participating entity the
instances of binary relationship.
1- Exactly one instances
M- Many instances
N- Any number of instances

Employee Works_for Department


Notation used in ER diagram for representing Relations
2. Min-max notation
• A (min, max) notation for binary relationship
specifies that entity is related to at least min, at most
max relationship instances in relation ship.
• The (min, max) constraints can determine keys for
binary relationship.

Employee Works_for Department

(1,1) - 1 Employee work for 1 Department


(1,N) - 1 Department having N Employees
EER
(Extended Entity
Relationship
model)
EER (Extended Entity Relationship model)
• EER is a high-level data model that incorporates
the extensions to the original ER model. Enhanced
ERD are high level models that represent the
requirements and complexities of complex
database.
• In addition to ER model concepts EE-R includes −
1. Subclasses and Super classes.
2. Specialization and Generalization.
3. Category or union type.
4. Aggregation.
1.Superclass – Subclass and Inheritance
1. Super Class
 Super class is an entity type that has a relationship with one or
more subtypes.
 An entity cannot exist in database merely by being member of
any super class.
 For example: Shape super class is having sub groups as Square,
Circle, Triangle.
2. Sub Class
 Sub class is a group of entities with unique attributes.
 Sub class inherits properties and attributes from its super
class.
 For example: Square, Circle, Triangle are the sub class of Shape
super class.
 The relationship between super class-sub class represented by
encircled ‘d’.
Superclass – Subclass and Inheritance
Superclass – Subclass and Inheritance
3. Inheritance
 Entity in subclass represent the same properties as its
super class.
 Subclass has some attribute as member of super class.
 Type of an entity is defined by attribute posses by a
relationship type in which they participates.
 The entity inhabits all relationship in which super
class participates.
 An entity that is member of subclass inhabits all
attribute of attributes of entity as a member of super
class.
Superclass v/s Subclass
Super Class Sub Class
A superclass is an entity from which A subclass is an entity that is derived
another entity can be derived. from another entity.
For example, an entity set account has For example, entities set
two subsets saving_account and saving_account and current_account
current_account. So an account is are derived from entity set account. So
superclass. saving_account and current_account
are subclass.
Super Class
Account

Saving_Account Current_Account

Sub Class
2. Generalization and Specialization
1. Generalization
 Generalization is the process of generalizing the
entities which contain the properties of all the
generalized entities.
 It is a bottom up approach, in which two lower level
entities combine to form a higher level entity.
 Generalization is the reverse process of Specialization.
 It defines a general entity type from a set of
specialized entity type.
 It minimizes the difference between the entities by
identifying the common features.
Generalization and Specialization
Generalization
 For Example,

 In the above example, Tiger, Lion, Elephant can all be


generalized as Animals.
Generalization and Specialization
2. Specialization
 Specialization is a process that defines a group
entities which is divided into sub groups based on
their characteristic.
 It is a top down approach, in which one higher entity
can be broken down into two lower level entity.
 It maximizes the difference between the members of
an entity by identifying the unique characteristic or
attributes of each member.
 It defines one or more sub class for the super class
and also forms the superclass/subclass relationship.
Generalization and Specialization
Specialization
 For example

 In the above example, Employee can be specialized as


Developer or Tester, based on what role they play in an
Organization.
Generalization and Specialization
Bottom-up approach Generalization
Top down approach
Specialization
Generalization v/s Specialization
• Generalization • Specialization
– It extracts the common – It splits an entity to form
features of multiple entities to multiple new entities that
form a new entity. inherit some feature of the
Name Address splitting entity.
Name Address

Person SPI Salary


Person
Name Name
ISA
Bottom-up approach

ISA
Address Address

Student Faculty Student Faculty

SPI Salary SPI Salary


Generalization v/s Specialization
Generalization Specialization
The process of creating groupings The process of creating sub-groupings
from within an entity set is called
various entity sets is called specialization.
generalization.
It will work in Bottom-up approach. It will work in Top-down approach.
Generalization is a process of taking Specialization is a process of taking a
the sub set of higher level entity set to
union of two or more lower-level form a lower-level entity set.
entity sets to produce a higher-level
entity set.
Generalization starts from the number Specialization starts from a single
of entity sets and creates high-level entity set; it creates different low-level
entity set using some common entity set using some different
features. features.
3. Category or Union
 Category represents a single super class or sub class relationship
with more than one super class.
 It can be a total or partial participation.
 For example Car booking, Car owner can be a person, a bank (holds
a possession on a Car) or a company. Category (sub class) → Owner
is a subset of the union of the three super classes → Company, Bank,
and Person. A Category member must exist in at least one of its super
classes.
4. Aggregation in E-R diagram
 Aggregation is meant to represent a relationship between a
whole object and its component parts.
 It is used when we have to model a relationship involving
entity sets and a relationship set.
Aggregation in E-R diagram
Work

EmpID Name Hours PID Name

Emp Work Project

Two relationship between same


Can not connect
pair of entities is not two
allowed
relationship

Uses Entity 1

Process of creating an
entity by combining Machinery Relation
various components
of E-R diagram is MID Entity 2
called aggregation.
Draw ER Diagram-
Example
Draw ER Diagram
Example: 1 A publication may be book or an article. Articles are
published in Journals has JID. Publication has title and location.
Book having their publisher_id, title and category. Article includes
title, topic and date. Publication is written by Authors stores
Name, address and mobile number. Publication also belongs to
particular subject which has their SID and names.
Solution:
Step:1 Identify Entities
1.Publication
2.Book
3.Article
4.Journal
5.Subject
6.Author
Draw ER Diagram
Step:2 Identify Attributes
1. Publication (title, location)
2. Book (Publisher_id, Title, Category)
3. Article (Title, Date, Topic)
4. Journal(JID)
5. Subject (SID, Name)
6. Author (Name, Address, Mobile Number)

Step:3 Identify Relationship


1. Article are published in journal.
2. Publication is written by Author
3. Publication belongs to a particular subject.
Draw ER Diagram
Step:4 Identify Inheritance relations.
Publication can be Books or Article.
Draw ER Diagram
Step:5 Merging all above relations we will get final ER model.
Draw ER Diagram
Example: 2 Draw ER Diagram for car insurance company that has a set
of customer each of whose having one or more car. Each car associated
with it zero to any number of record accidents.
Solution:
Step:1 Identify Entities.
1.Car
2.Insurance company
3.Customer
4.Accidents
Step:2 Identify Attributes
1.Car (car_no. , car_model, car_owner)
2.Insurance company (Company_id, company_name, company_address)
3.Customer (cus_name,cus_address, cus_id))
4.Accidents (acd_id, acd_place)
Draw ER Diagram
Step:3 Identify Relationships.
1.car insurance company that has a set of customer
2.customer each of whose having one or more car.
3.Each car associated with it zero to any number of record
accidents.
Draw ER Diagram
Step:4 Merging all above relations we will get final ER model.
Draw ER Diagram
Example: 3 Draw ER Diagram for hospital with a set of patients
and the set of medical doctors associated with each patient a
record of various text and examination conducted.
Solution:
Step:1 Identify Entities.
1.Hospital
2.Patient
3.Doctor
4.Record
Step:2 Identify Attributes
1.Hospital (Hos_id,Hos_Nmae,Hos_address)
2.Patient (Paddress,p_name,P_diagnosis)
3.Doctor (D_id,D_name,D_address,Salary,D_qualifiaction)
4.Record ((examination_date,problem,record_id)
Draw ER Diagram
Step:3 Identify Relationships.
1.Hospital with a set of patients
2.Hospital with a set of doctor
3.Doctors associated with each patient
4.Patient a record of various text and examination conducted.
Draw ER Diagram
Step:4 Merging all above relations we will get final ER model.
Draw ER Diagram
Example: 4 Draw ER Diagram for University database consisting
for entities Student, Department, Class and Faculty.
Student has unique id, the student can enroll for multiple classes
and has a most one major. Faculty must belong to department and
faculty can teach multiple classes. Each class is taught by only
faculty. Every student will get grade for the class he/she has
enrolled.
Solution:
Step:1 Identify Entities.
1.Department
2.Student
3.Class
4.Faculty
5.Grade
6.Major
Draw ER Diagram
Step:2 Identify Attributes
1.Department(DID, Dname)
2.Student (unique_id, Sname, SAddress ,SDOB)
3.Class (CID,Number)
4.Faculty (FID, Fname, Fsalary)
5.Grade (GNo,Marks)

Step:3 Identify Relationships.


1.Student can enroll for multiple classes
2.Faculty must belong to department
3.Each class is taught by only faculty
4.Every student will get grade
5.Student most one major
Draw ER Diagram
Step:4 Merging all above relations we will get final ER model.
Example-5 E-R diagram for Banking Enterprise
Example-5 E-R diagram for Banking Enterprise
Example-6 E-R diagram for Computer Shop
E-R diagram of Hospital
PatID Name HosID Name

Patient Admitted Hospital

ISA Has
RoomNo

Indoor Outdoor
Doctor
Has
IPDID OPDID
DrID Dr Name
Medical Record

MRID Report Name


ER Diagram for
School
Management
System
Types of Integrity Constraints
Different types
of Model
1.Hierarchical Model
 The data stored hierarchically, either in top down or bottom up
approach of designing.
 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.
Hierarchical Model
Hierarchical Model
2.Network Model
 This is an extension of the Hierarchical model.
 This model also uses pointers towards data but before there is
no need of parent to child association so it does not necessarily
use a downward tree structure.
 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.
Network Model
Network Model
 There are two concept involved in network model:
SET: A relationship between any two record types is called as a set.
RECORD:
1. Owner record is like parent record in hierarchical model.
Example: Professor teaches to students in this case professor is
owner entity.
2. Parent record is like child record in hierarchical model.
Example: Professor teaches to students in this case student in
parent entity.
3.Relational Model
 This model was introduced by E.F Codd in 1970, and since then
it has been the most widely used database model.
 Relational model can represent as a table with columns and
rows. Each row is known as a tuple. Each table of the column
has a name or attribute.
 In this model, data is organised in two-dimensional tables and
the relationship is maintained by storing a common field.
 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.
 This Model uses collection of tables to represent relationship
amongst the data.
Relational Model
 Domain: It contains a set of atomic values that an attribute can
take.
 Attribute: It contains the name of a column in a particular
table. Each attribute Ai must have a domain, dom(Ai)
 Relational instance: In the relational database system, the
relational instance is represented by a finite set of tuples.
Relation instances do not have duplicate tuples.
 Relational schema: A relational schema contains the name of
the relation and name of all columns or attributes.
 Relational key: In the relational key, each row has one or more
attributes. It can identify the row in the relation uniquely.
Relational Model

In the given table, NAME, ROLL_NO, PHONE_NO, ADDRESS, and AGE are the
attributes.

The instance of schema STUDENT has 5 tuples.

t3 = <Laxman, 33289, 8583287182, Gurugram, 20>


Relational Model
Properties of Relations:
 Name of the relation is distinct from all other
relations.
 Each relation cell contains exactly one atomic (single)
value
 Each attribute contains a distinct name
 Tuple has no duplicate value
 Order of tuple can have a different sequence
4. Object oriented Model
 The data is stored in the form of objects, Which are
structures called Classes that display the data within
it.
 The fields are instances of these called as objects.
 This model is used in file management systems.
Integrity
Constraints
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 Integrity Constraint
Types of Integrity Constraints
1. Domain constraints
 Domain constraints can be defined as the definition of a valid
set of values for an attribute.
 The data type of domain includes string, character, integer,
time, date, currency, etc. The value of the attribute must be
available in the corresponding domain.
 Example:
Types of Integrity Constraints
2. Entity integrity constraints
 The entity integrity constraint states that primary key value
can't be null.
 This is because the primary key value is used to identify
individual rows in relation and if the primary key has a null
value, then we can't identify those rows.
 A table can contain a null value other than the primary key
field.
 Example:
Types of Integrity Constraints
3. Referential Integrity Constraints
 A referential integrity constraint is specified between two tables.
 In the Referential integrity constraints, if a foreign key in Table 1
refers to the Primary Key of Table 2, then every value of the Foreign
Key in Table 1 must be null or be available in Table 2.
 Example
Types of Integrity Constraints
4. Key constraints
 Keys are the entity set that is used to identify an entity within
its entity set uniquely.
 An entity set can have multiple keys, but out of which one key
will be the primary key. A primary key can contain a unique and
null value in the relational table.
 Example:

You might also like