Unit 2
Unit 2
Data Models:
Data models describe how a database’s logical structure is represented. In a database management
system, data models are essential for introducing abstraction. Data models specify how data is linked
to one another, as well as how it is handled and stored within the system.
Hierarchical Model
1. Parent-Child Relationship
A parent node exists for each child node. However, a parent node might have several child nodes. It
is not permitted to have more than one parent.
2. One-to-many Relationship
The data is organised in a tree-like form, with the datatypes having a one-to-many relationship.
There can only be one path from any node to its parent. For example, in the preceding example,
there is only one way to get to the node ‘sneakers’, which is through the ‘men’s shoes’ node.
3. Deletion Problem
4. Pointers
Pointers are used to connect the parent and child nodes and to traverse and navigate between the
stored data. The ‘shoes’ node in the above example points to the two additional nodes, ‘women’s
shoes’ and ‘men’s shoes.’
• Any modification to the parent node is reflected automatically in the child node, ensuring
data integrity.
Network model:
The network model was devised to express complicated data relationships more effectively than
hierarchical models. It has entities that are grouped in a graphical format, and some of the entities
can be reached by many paths.
1. Multiple Paths
There may be several paths to the same record due to the increased number of relationships. It
allows for quick and easy data access.
Data is more connected in this model since there are more relationships. This paradigm can handle
many-to-many as well as one-to-one relationships
• In comparison to the hierarchical model, data can be retrieved faster. This is because the
data in the network model is more related, and there may be more than one path to a given
node. As a result, the data can be accessed in a variety of ways.
• Data integrity is present since there is a parent-child relationship. Any changes to the parent
record are mirrored in the child record.
• As the number of relationships to be managed grows, the system may get increasingly
complicated. To operate with the model, a user must have a thorough understanding of it.
2. Database Design – This approach is extensively used in database design and aids database
designers in the creation of databases.
1. Simple – The ER Model is simple to construct conceptually. We can easily construct the ER
Diagram for the model if we know the relationship between the entities and the attributes.
2. Effective communication tool – Database designers frequently employ this model to communicate
their thoughts.
3. Easy conversion to any model – This model translates neatly to the relational model, and it is
simple to transform the ER model into a table. This model can be transformed into a network model,
a hierarchical model, and so forth.
1. No industry standard for notation – When it comes to creating an ER model, there is no industry
standard. As a result, one developer may utilise notations that are unfamiliar to other developers.
2. Hidden information – In the ER model, certain information may be lost or hidden. Because it is a
high-level view, there is a potential that some information specifics will be buried.
E-R Model:
Symbols Used in ER Model
ER Model is used to model the logical view of the system from a data perspective which consists of
these symbols:
• Lines: Lines represent attributes to entities and entity sets with other relationship types.
Components of ER Diagram
ER Model consists of Entities, Attributes, and Relationships among Entities in a Database System.
What is Entity?
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 is an object of Entity Type and a set of all entities is called an entity set. For Example, E1 is
an entity having Entity Type Student and the set of all students is called Entity Set. In ER diagram,
Entity Type is represented as:
Types of Entity
1. Strong Entity
A Strong Entity is a type of entity that has a key Attribute. Strong Entity does not depend on other
Entity in the Schema. It has a primary key, that helps in identifying it uniquely, and it is represented
by a rectangle. These are called Strong Entity Types.
2. Weak Entity
For Example, A company may store the information of dependents (Parents, Children, Spouse) of an
Employee. But the dependents can’t exist without the employee. So Dependent will be a Weak
Entity Type and Employee will be Identifying Entity type for Dependent, which means it is Strong
Entity Type .
A weak entity type is represented by a Double Rectangle. The participation of weak entity types is
always total. The relationship between the weak entity type and its identifying strong entity type is
called identifying relationship and it is represented by a double diamond.
What is Attributes?
Attributes are the properties that define the entity type. For example, Roll_No, Name, DOB, Age,
Address, and Mobile No. are the attributes that define entity type Student. In ER diagram, the
attribute is represented by an oval.
Types of Attributes
1. Key Attribute
The attribute which uniquely identifies each entity in the entity set is called the key attribute. For
example, Roll_No will be unique for each student. In ER diagram, the key attribute is represented by
an oval with underlying lines.
2. Composite Attribute
An attribute composed of many other attributes is called a composite attribute. For example, the
Address attribute of the student Entity type consists of Street, City, State, and Country. In ER diagram,
the composite attribute is represented by an oval comprising of ovals.
3. Multivalued Attribute
An attribute consisting of more than one value for a given entity. For example, Phone_No (can be
more than one for a given student). In ER diagram, a multivalued attribute is represented by a double
oval.
4. Derived Attribute
An attribute that can be derived from other attributes of the entity type is known as a derived
attribute. e.g.; Age (can be derived from DOB). In ER diagram, the derived attribute is represented by
a dashed oval.
The Complete Entity Type Student with its Attributes can be represented as:
A Relationship Type represents the association between entity types. For example, ‘Enrolled in’ is a
relationship type that exists between entity type Student and Course. In ER diagram, the relationship
type is represented by a diamond and connecting the entities with lines.
A set of relationships of the same type is known as a relationship set. The following relationship set
depicts S1 as enrolled in C2, S2 as enrolled in C1, and S3 as registered in C3.
The number of different entity sets participating in a relationship set is called the degree of a
relationship set.
1. Unary Relationship: When there is only ONE entity set participating in a relation, the relationship
is called a unary relationship. For example, one person is married to only one person.
2. Binary Relationship: When there are TWO entities set participating in a relationship, the
relationship is called a binary relationship. For example, a Student is enrolled in a Course.
3. Ternary Relationship: When there are three entity sets participating in a relationship, the
relationship is called a ternary relationship.
4. N-ary Relationship: When there are n entities set participating in a relationship, the relationship is
called an n-ary relationship.
What is Cardinality?
The number of times an entity of an entity set participates in a relationship set is known
as cardinality . Cardinality can be of different types:
1. One-to-One: When each entity in each entity set can take part only once in the relationship, the
cardinality is one-to-one. Let us assume that any Surgeon can headed by only one HOD. So the
relationship will be one-to-one.
2. One-to-Many: In one-to-many mapping as well where each entity can be related to more than one
entity and the total number of tables that can be used in this is 2. Let us assume that one surgeon
department can accommodate many doctors. So the Cardinality will be 1 to M. It means one
department has many Doctors.
total number of tables that can used is 3.
3. Many-to-One: When entities in one entity set can take part only once in the relationship set and
entities in other entity sets can take part more than once in the relationship set, cardinality is many
to one.
In this case, each student is taking only 1 course but 1 course has been taken by many students.
4. Many-to-Many: When entities in all entity sets can take part more than once in the relationship
cardinality is many to many. Let us assume that a student can take more than one course and one
course can be taken by many students. So the relationship will be many to many.
In this example, student S1 is enrolled in C1 and C3 and Course C3 is enrolled by S1, S3, and S4. So it
is many-to-many relationships.
Participation Constraint
1. Total Participation – Each entity in the entity set must participate in the relationship. If each
student must enroll in a course, the participation of students will be total. Total participation is
shown by a double line in the ER diagram.
2. Partial Participation – The entity in the entity set may or may NOT participate in the relationship.
If some courses are not enrolled by any of the students, the participation in the course will be partial.
The diagram depicts the ‘Enrolled in’ relationship set with Student Entity set having total
participation and Course Entity set having partial participation.
Every student in the Student Entity set participates in a relationship but there exists a course C4 that
is not taking part in the relationship.
Super Key
The set of one or more attributes (columns) that can uniquely identify a tuple (record) is known
as Super Key.
• A super key is a group of single or multiple keys that uniquely identifies rows in a table. It
supports NULL values in rows.
• A super key can contain extra attributes that aren’t necessary for uniqueness.
Candidate Key
The minimal set of attributes that can uniquely identify a tuple is known as a candidate key.
• A candidate key is a minimal super key, meaning it can uniquely identify a record but
contains no extra attributes.
• A candidate key must contain unique values, ensuring that no two rows have the same value
in the candidate key’s columns.
• A table can have multiple candidate keys but only one primary key
Primary Key
There can be more than one candidate key in relation out of which one can be chosen as the primary
key.
• A primary key is a unique key, meaning it can uniquely identify each record (tuple) in a table.
• It must have unique values and cannot contain any duplicate values.
• A primary key cannot be NULL, as it needs to provide a valid, unique identifier for every
record.
• A primary key does not have to consist of a single column. In some cases, a composite
primary key (made of multiple columns) can be used to uniquely identify records in a table.
• Databases typically store rows ordered in memory according to primary key for fast access of
records using primary key.
Alternate Key
An alternate key is any candidate key in a table that is not chosen as the primary key. In other
words, all the keys that are not selected as the primary key are considered alternate keys.
• An alternate key is also referred to as a secondary key because it can uniquely identify
records in a table, just like the primary key.
• An alternate key can consist of one or more columns (fields) that can uniquely identify a
record, but it is not the primary key
Unique key :
It uniquely identifies a tuple in a relation. Unlike the Primary key, There can be more than one unique
key in a table. It can accept only one null value. It cannot have duplicate values and it is non-
updatable i.e. cannot be updated once it is assigned.
Example –
The best example of unique key is Voter ID.
Voter Id is unique for all the citizens. If it gets lost and another duplicate copy is issued, then the
duplicate copy always has the same number as before. Thus, it is non-updatable. Few citizens may
not have got their Voter Id, so for them, its value is NULL.
1 Akon CS AX 9876723452 17
2 Tkon EC BX 9991165674 19
4 Ckon ME DX 8987867898 19
5 Dkon EE FX 9990080080 17
*Student_id and phone both are candidate keys for table Student.
*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 this example student_id will be the Primary
key.
*The candidate key which are not selected as primary key are known as secondary keys or alternative
keys.