Chp2 Data Models
Chp2 Data Models
🞂 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.)
🞂 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.
🞂 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 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 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.
🞂 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)
🞂 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.
🞂 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.
🞂 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 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
🞂 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.
🞂 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.
🞂 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.
🞂 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)
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
🞂 Efficiency
Disadvantages
🞂 Implementation complexity
🞂 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.
🞂 All the information related to a particular type is stored in rows of that table.
🞂 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.
🞂 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 was the most widely used database model, before Relational Model was introduced.
Continued…
Network Model