Chapter2_DatabaseSystemConceptsAndArchitecture
Chapter2_DatabaseSystemConceptsAndArchitecture
MANAGEMENT
SYSTEM
Subash Manandhar
1
Chapter 2 – Data Models
• 2.1 Logical, Physical and Conceptual Model
• Data Model :
• Is a collection of conceptual tools for describing data, data relationships,
semantics etc.
• Is a simple representation of complex real world data structure.
• It is a communication tool to facilitate interaction among the designer, the
application programmers and the end users.
• It defines how data is connected to each other and how it will be
processed and stored inside the system.
• 3 level of data modeling:
• Conceptual Data Model
• Logical Data Model
• Physical Data Model
Subash Manandhar 2
Chapter 2 – Data Models
• 2.1 Logical, Physical and Conceptual Model
• Conceptual Data Model :
• Identifies the highest level relationship between different entities.
• Includes important entities and their relationships.
• No attributes and primary key is specified.
• Logical Data Model :
• Describes the data in as much detail as possible, without saying much about
their physical implementation.
• It includes all the entities and relationship among them.
• All attributes for each entity are specified.
• Primary key and foreign key are also specified.
• Physical Data Model :
• Represents how the model will be built in the database.
• Shows all table structures, including column name, data type constraints,
primary key, foreign key and their relationship between tables.
Subash Manandhar 3
Chapter 2 – Data Models
• 2.1 Logical, Physical and Conceptual Model
Subash Manandhar 4
Chapter 2 – Data Models
• 2.1 Logical, Physical and Conceptual Model
• e.g. to store information of students, courses and also keep track of
courses taken by students.
student course student course
Roll CID
Name Name
Address Description
Phone Credit hr.
stu_course stu_course
St_Course
fig: _ID
fig: Logical
Conceptual
Data Model Roll (FK)
Data Model
CID (FK)
Subash Manandhar 5
Chapter 2 – Data Models
• 2.1 Logical, Physical and Conceptual Model
• e.g. to store information of students, courses and also keep track of
courses taken by students.
tbl_student tbl_course
Roll : integer (PK) CID : integer (PK)
Name : string Name : string
Address : string Description : string
Phone : integer Credit hr. : integer
tbl_stu_course
St_Course_ID : integer (PK)
Roll : integer (FK) fig: physical data model
CID : integer (FK)
Subash Manandhar 6
Chapter 2 – Data Models
• 2.4 Alternate Data Models
• Hierarchical Data Model :
• It organizes data in tree structure where there is a hierarchy of parent and child data
segments.
• It has a single root segment connected to lower level segments.
• Each segment may connect to other lower level segments.
• Here, rule is that one parent can have many children but children are allowed only one
parent.
• This allows information to be repeated through the parent child relation.
• Advantages:
• Allows easy addition and deletion of new information.
• Fast access to data at top.
• Relates well to anything that works on one to many relationship.
• Disadvantages:
• Allows data redundancy.
• Searching for lower level information is slow.
• Many to many relationships are not supported.
Subash Manandhar 7
Chapter 2 – Data Models
• 2.4 Alternate Data Models
• Hierarchical Data Model :
Student
Subash Manandhar 8
Chapter 2 – Data Models
• 2.4 Alternate Data Models
• Network Data Model :
• Replaces the hierarchical tree with graph.
• Allows to have more than one parent.
• Advantages:
• Simple and easy to implement.
• Can handle one to one and many to many relationship.
• Data access is easier than hierarchical model.
• Disadvantages:
• System complexity so difficult to handle and maintain.
• Lack of structural independence i.e. change in structure makes change in
applications too.
Subash Manandhar 9
Chapter 2 – Data Models
• 2.4 Alternate Data Models
• Network Data Model :
Student
C1 DBMS C2 OOP
Subash Manandhar 10
Chapter 2 – Data Models
• 2.4 Alternate Data Models
• Relational Data Model :
• All data are stored in tables where each table consists of row and columns.
• Here, keys are used to order data or relate data to other tables.
• Defines set of rules to enforce data integrity, known as integrity constraints.
• Also defines how data are manipulated.
• Defines special feature called normalization to ensure efficient data storage.
• Advantages:
• Easy to use.
• Flexibility
• Security
• Data independence
• Disadvantages:
• Ease of design can lead to bad design
• Hardware overheads.
Subash Manandhar 11
Chapter 2 – Data Models
• 2.4 Alternate Data Models
• Relational Data Model :
Subash Manandhar 13
Chapter 2 – Data Models
• 2.4 Alternate Data Models
• Object Oriented Data Model :
Student Course
1 Enrolled in 1..*
Roll : integer Course_ID: integer
Name : string Name : string
Subash Manandhar 14
Chapter 2 – Data Models
• 2.2 E-R (Entity Relationship) Model
• Defines the conceptual view of database.
• Works around real world objects called entities and relationship among
them.
• Entity :
• A real world thing that is easily identifiable and distinguishable.
• Entity set is a collection of similar types of entities.
• Entity sets do not need to be disjoint.
• e.g. entity set of employee and entity set of customer may have members in common.
• Attributes:
• are the properties of entities.
• Simple attribute:
• Which can not be divided further
• e.g. phone no.
Subash Manandhar 15
Chapter 2 – Data Models
• 2.2 E-R (Entity Relationship) Model
• Attributes:
• Composite attribute:
• Made of more than one simple attribute
• e.g. name where name can be further divided into first name , last name
• Derived attribute:
• Do not exist in physical database but value is derived from other attributes.
• e.g. age where age can be derived from dob (date of birth)
• Single valued attribute:
• Which have only one value.
• e.g. citizenship no.
• Multi valued attribute:
• Which can have more than one value.
• e.g. email, phone no.
Subash Manandhar 16
Chapter 2 – Data Models
• 2.2 E-R (Entity Relationship) Model
• Attributes:
• Domain of attribute is set of permitted values.
• e.g. mobile no. must have 10 digits.
• Relationship:
• is association among the entities.
• Relationship set is a set of relationship of same type.
• Degree of relationship:
• It refers the number of entity sets that participate in a relationship.
• Unary relationship is of degree 1 that involves only one entity set.
• Binary relationship is of degree 2.
• Ternary relationship is of degree 3.
• Relationships in database are often binary.
• It is possible to replace a non binary (n-ary ; n>2) relationship set by a number of distinct
binary relationship set.
Subash Manandhar 17
Chapter 2 – Data Models
• 2.2 E-R (Entity Relationship) Model
• ER Diagram :
• Is a data modeling technique that creates a graphical representation of entities
and the relationship between entities, within an information system.
• Illustrates the logical structure of database.
• Major components are
• Rectangles - => to represent entity set
• Diamonds -
=> to represent relationship set
Subash Manandhar 18
Chapter 2 – Data Models
• 2.2 E-R (Entity Relationship) Model
• ER Diagram :
• Lines - => to link attributes to entity sets and entity sets to
relationship set
• Dashed Ellipses -
=> to represent derived attributes
Subash Manandhar 19
Chapter 2 – Data Models
• 2.2 E-R (Entity Relationship) Model
• e.g.
• Entity :
• Driver , Taxi
• Attributes:
For Driver For Taxi
license no chasis no
name company
address model
phone color
• Relationship:
• Driver drives Taxi. So, relationship between Driver and Taxi is drives.
Subash Manandhar 20
Chapter 2 – Data Models
• 2.2 E-R (Entity Relationship) Model
• e.g. ER Diagram
• Entity:
Driver Taxi
• Attributes:
• Relationship :
drives
Subash Manandhar 21
Chapter 2 – Data Models
• 2.2 E-R (Entity Relationship) Model
• e.g. ER Diagram
Subash Manandhar 22
Chapter 2 – Data Models
2.2 ER Model
• The role of an entity is the function it plays in relationship.
Name
Phone
SSN
City
Manager
Works
Employee for
Worker
Here, ‘Manager’ and ‘Worker’ are roles of entity Employee in Works for
relationship.
roles are optional and clarify semantics of a relationship.
Subash Manandhar 23
Chapter 2 – Data Models
2.2 ER Model
• Mapping Cardinalities
• express the number of entities to which another entity can be associated
through a relationship set.
• For binary relationship set R between entity set A and B, the mapping
cardinality must be one of the following:
• One to One
• An entity in A is associated with at most one entity in B and vice-versa.
• One to many
• An entity in A can be associated with more than one entities of entity set B but
from entity set B one entity can be associated with at most one entity in A.
• Many to One
• More than one entities from entity set A can be associated with at most one
entity of entity set B but one entity from entity set B can be associated with
more than one entity from entity set A.
• Many to many
• One entity from entity set A can be associated with more than one entity from
entity set B and vice-versa.
Subash Manandhar 24
Chapter 2 – Data Models
2.2 ER Model
• Mapping Cardinalities • Mapping Cardinalities
• One to One • Many to One
A Q A Q
B R B R
C S C S
D T D T
A Q A Q
B R B R
C S C S
T D T
Subash Manandhar 25
Chapter 2 - Data Models
2.2 ER Model
• One to One Relationship
Subash Manandhar 26
Chapter 2 - Data Models
2.2 ER Model
• One to Many Relationship
Subash Manandhar 27
Chapter 2 - Data Models
2.2 ER Model
• Many to One Relationship
Published
Books Publisher
By
Subash Manandhar 28
Chapter 2 - Data Models
2.2 ER Model
• Many to Many Relationship
Subash Manandhar 29
Chapter 2 – Data Models
2.2 ER Model
• Participation Constraints:
• Constraints that determine whether all or only some entity occurrences
participate in a relationship.
• Two Types:
• Total participation
• If every entity in entity set E participates in relationship at least once.
• Partial participation
• If only some entities in entity set E participate in relationship.
S_No
B_No
Branch Is
Staff
allocated
Subash Manandhar 31
Chapter 2 – Data Models
2.2 ER Model
Strong Entity Set Weak Entity Set
• It has its own primary key. • It doesn’t have sufficient
attributes to form a primary key on
its own.
• It Is represented by double
• It is represented by a rectangle.
rectangle.
• Contains a partial key or
• Contains a primary key discriminator represented by
represented by underline. dashed underline.
• Its member is called Dominant • Its member is called Subordinate
entity set. entity set.
• Primary key is one of attributes • Primary key is combination of
that uniquely identify its members. partial key and primary key of
strong entity set.
Subash Manandhar 32
Chapter 2 – Data Models
2.2 ER Model
Strong Entity Set Weak Entity Set
• Total participation in relationship • Total participation always exists.
may or may not exist.
• Relationship between two strong • Relationship between one strong
entity set is represented by and one weak entity set is
diamond symbol. represented by double diamond
symbol.
• Single line connects strong entity • Double line connects weak entity
set with relationship. set with relationship.
• Idea of strong and weak entity set is related to the existence dependencies.
• If the existence of entity A depends on existence of entity B, then A is existence
dependent on B.
Subash Manandhar 33
Chapter 2 - Data Models
2.2 ER Model
• e.g.
AccNo Acc_name
Amount
TNo
Balance
Date
Subash Manandhar 35
Chapter 2 – Data Models
2.2 ER Model
• e.g.
• A company has several departments. Each department has a
supervisor and at least one employee. Employees must be assigned
to at least one but possibly more departments. At least one
employee is assigned to a project, but an employee may be on
vacation and not assigned to any projects. The important data fields
are names of departments, projects, supervisors and employees, as
well as the supervisor and employee number and a unique project
no.
Subash Manandhar 36
Chapter 2 – Data Models
2.2 ER Model
• Solution:
• Identify Entities:
• Company , Department, Supervisor, Employee, Project
• Find Relationship:
Subash Manandhar 37
Chapter 2 – Data Models
2.2 ER Model
• Solution:
• Draw rough ERD:
run
Department Supervisor
by
is
Department Employee
assigned
works
Employee Project
on
Subash Manandhar 38
Chapter 2 – Data Models
2.2 ER Model
• Solution:
Supervisor
• Draw rough ERD:
run
Company has Department
by
is
assigned
works
Project Employee
on
Subash Manandhar 39
Chapter 2 – Data Models
2.2 ER Model
• Solution:
• Fill cardinality:
One and only one One or more
Subash Manandhar 40
Chapter 2 – Data Models
2.2 ER Model
• Solution:
Supervisor
• Fill cardinality:
run
Company has Department
by
is
assigned
works
Project Employee
on
Subash Manandhar 41
Chapter 2 – Data Models
2.2 ER Model
• Solution:
• Identify attributes and define primary keys:
• Employee-name (ename)
• Project-name (pname)
• Supervisor-name (sname)
• Department-name (dname)
• Employee-no (eid)
• Project-no (pid)
• Supervisor-no (sid)
Subash Manandhar 42
Chapter 2 – Data Models sid sname
2.2 ER Model
• Solution:
Supervisor
• Map and Draw fully attributed ER Diagram:
dname
run
Company has Department
by
is
pid pname assigned
works
Project Employee
on
eid ename
Subash Manandhar 43
Chapter 2 – Data Models
2.2 ER Model
• e.g.
• Consider a bus ticketing system that records information about the
passenger, bus and route. Passenger is assigned to a bus that travels to
route. A bus contains many passengers and a passenger can be assigned
into only one bus. Many buses travel in same route but a bus can travel in
only one route. The attributes of passenger are pid(Primary Key), gender
and telephone(multi-valued). Similarly, bus contains reg.no(Primary Key)
and color and route contains rid(Primary Key), distance and rate. Now
construct a clean and concise ER diagram with clear cardinality mappings.
Subash Manandhar 44
Chapter 2 – Data Models
2.2 ER Model
• EER (Extended or Enhanced ER) Model
• Is the ER model combined with the additional features of semantic
concepts.
• Shows complex relationship between objects in a database.
• Some additional concepts in EER model are:
• 1. Specialization 2. Generalization 3. Categorization
Subash Manandhar 45
Chapter 2 – Data Models
2.2 ER Model
Shared
attributes
Superclass
Person
Salary
Roll No.
Credit
Rating
Office Hrs.
Faculty BE ME
no. worked
Subash Manandhar 47
Chapter 2 – Data Models
2.2 ER Model
• Specialization
• Is a means of identifying sub groups within an entity set which have unique
attributes.
• Is a top down process.
• Is a process of defining one or more subclasses from the superclass and
forming superclass subclass relationship.
• In EER diagram, it is represented by a triangle component labeled ISA or
simply circle with U symbol.
• Generalization
• Is a bottom up approach opposite to specialization.
• Is the process of forming a superclass.
• It emphasize the similarities among lower level entity set and hide the
difference.
Subash Manandhar 48
Chapter 2 – Data Models
2.2 ER Model
• Specialization Address Name Phone
Person
Person
Employee Student
Subash Manandhar 49
Chapter 2 – Data Models
2.2 ER Model
• Generalization Price Model Name
Car
Registration
Company No.
No. of
Passenger
Truck
Company Capacity
Registration
No.
Subash Manandhar 50
Chapter 2 – Data Models
2.2 ER Model
• Generalization Price Model Name
Vehicle
Registration
Company No.
ISA
Car Truck
No. of
Passenger Capacity
Subash Manandhar 51
Chapter 2 – Data Models
2.2 ER Model
• Attribute Inheritance:
• Is a crucial property of superclass and subclass.
• Attributes of superclass are said to be inherited by subclasses.
• Single Inheritance:
• Also called as hierarchy.
• Defines that every subclass has only one super class.
• Multiple Inheritance:
• Also called as lattice.
• Defines that subclass can have more than one super class.
• A subclass with more than one superclass is called Shared Subclass.
Subash Manandhar 52
Chapter 2 – Data Models
2.2 ER Model
Employee Employee
ISA ISA
Subash Manandhar 53
Chapter 2 – Data Models
2.2 ER Model
Disjoint Constraint Overlapping Constraint
• Subclass belong to no more than • Subclass may belong to more than
one lower level entity set. one lower level entity set.
• Is represented by placing ‘d’ in • Is represented by placing ‘o’ in
circle or simply by ISA relationship. circle or simply by ISA relationship.
Account Person
d o
Subash Manandhar 54
Chapter 2 – Data Models
2.2 ER Model
Total generalization/specialization Partial generalization/specialization
• Every entity in superclass must be • Every entity in superclass may not
member of at least one subclass. belong to subclass.
• Double lines are used to connect • Single line is used to connect
superclass to the circle. superclass to the circle.
Patient Vehicle
Subash Manandhar 55
Chapter 2 – Data Models
2.2 ER Model
• Categorization (Union Types)
• Models a class/subclass with more than one superclass of distinct entity
types.
• Subclass is called category.
• Only one subclass exists in categorization.
• Attribute inheritance is selective.
• Category members must exist in at least one of its superclass
Person Organization
U
Here, category Customer is subclass of
∪ Union of Person, Organization
Customer
Subash Manandhar 56
Chapter 2 – Data Models
2.2 ER Model
• Aggregation:
• Is an abstraction through which relationships are treated as high level entities.
• e.g. employee works on project and use no. of machine during that work.
• One way of solution is as below:
Works
employee project
on
use
Here, problem is {employee, project}
combination that appears in works
on relationship also appear in use
relationship.
machine
Subash Manandhar 57
Chapter 2 – Data Models
2.2 ER Model
• Aggregation:
• Now, solution is using aggregation, as below.
Works
Works
employee project
on
use
Here, relationship set Works on and
entity sets employee and project are
treated as high level entity called
Works.
machine
Subash Manandhar 58
Chapter 2 – Data Models
2.3 Relation with UML class diagram
• UML:
• Stands for Unified Modeling Language.
• is a standard language for specifying, visualizing, constructing, and
documenting the artifacts of software systems.
• UML is a modern approach to modeling and documenting software.
• It is based on diagrammatic representations of software components.
• There are several types of UML diagrams like Class Diagram, Use Case
Diagram, Sequence Diagram, Activity Diagram etc.
• Class Diagram:
• It shows the classes in a system, attributes, and operations of each class
and the relationship between each class.
• In class diagram, Name is at the top, attributes in the middle and
operations or methods at the bottom.
Subash Manandhar 59
Chapter 2 – Data Models
2.3 Relation with UML class diagram
• UML notations for ER Models:
• Entities are modeled as a class ; The name of the class is the entity name
and the attributes of the class are the entity’s attributes.
• The name and attributes can be arranged in a box style
• Relationships are shown as a single solid line connecting the two entities.
• The minimum and maximum cardinalities are shown along the line and
verb phrases can be added to completely characterize the nature of the
relationship.
• e.g.
• One Publisher May be publishing one or more Books
• One Book Must be published by One and Only One Publisher
Subash Manandhar 60
Chapter 2 – Data Models
2.3 Relation with UML class diagram
• ER Model or ER Diagram
Published
Books Publisher
By
Subash Manandhar 61
Chapter 2 – Data Models
2.3 Relation with UML class diagram
• UML Class Diagram
Books Publisher
Book_id (pk) Publisher_id (pk)
Title Published By 1..1 Name
Author 1.. * Publishes Location
Price
Subash Manandhar 62
Chapter 2 – Data Models
2.3 Relation with UML class diagram
• UML Class Diagram for above ER Diagram example
assigned to 1..*
Project Employee
involves 1..*
pid(pk) eid(pk)
pname 0..* works on ename
Subash Manandhar 63