0% found this document useful (0 votes)
7 views53 pages

2 UnitII DBMS

The document provides an overview of database design using the Entity-Relationship (ER) model, explaining key concepts such as entities, attributes, and relationships. It details various types of attributes (key, composite, multivalued, and derived) and relationship types (unary, binary, n-ary) along with data models including hierarchical, network, and relational models. Additionally, it covers the significance of ER diagrams in visualizing data structures and relationships within a database.

Uploaded by

laexistencia2810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views53 pages

2 UnitII DBMS

The document provides an overview of database design using the Entity-Relationship (ER) model, explaining key concepts such as entities, attributes, and relationships. It details various types of attributes (key, composite, multivalued, and derived) and relationship types (unary, binary, n-ary) along with data models including hierarchical, network, and relational models. Additionally, it covers the significance of ER diagrams in visualizing data structures and relationships within a database.

Uploaded by

laexistencia2810
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 53

Unit II Database design using ER Model

• Entity, Entity Type, Entity Set –

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


house, or employee

• 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 set of all entities is called as entity set.
• e.g. E1 is an entity having Entity Type Student and set of all students is called
Entity Set. In ER diagram, Entity Type is represented as:

• E1
• 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.

• 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.
• 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, 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.
• The complete entity type Student with its attributes can be represented as:

• Data association between entities
• 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, relationship type is represented by a diamond and connecting the
entities with lines.


• A set of relationships of same type is known as relationship set. The following
relationship set depicts S1 is enrolled in C2, S2 is enrolled in C1 and S3 is enrolled
in C3.

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

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

• 3. n-ary Relationship –
When there are n entities set participating in a relation, the relationship is called
as n-ary relationship.
• Data Model
• Data Model gives us an idea that how the final system will look like after its
complete implementation.

• It defines the data elements and the relationships between the data elements.

• Data Models are used to show how data is stored, connected, accessed and
updated in the database management system.

• Hierarchical Model
• Network Model
• Entity-Relationship Model
• Relational Model
• Object-Oriented Data Model
• Hierarchical Model
• Hierarchical Model was the first DBMS model.

• This model organises the data in the hierarchical tree structure.

• The hierarchy starts from the root which has root data and then it expands in
the form of a tree adding child node to the parent node.

• This model easily represents some of the real-world relationships like food
recipes, sitemap of a website.
• This model easily represents some of the real-world relationships like food
recipes, sitemap of a website etc.

• Example: We can represent the relationship between the shoes present on a


shopping website in the following way:
• Features of a Hierarchical Model
• One-to-many relationship:
• The data here is organised in a tree-like structure where the one-to-many
relationship is between the datatypes.
• There can be only one path from parent to any node.
• Example: In the above example, if we want to go to the node sneakers we only
have one path to reach there i.e through men's shoes node.

• Parent-Child Relationship:
• Each child node has one parent node but a parent node can have more than one
child node.
• Multiple parents are not allowed.
• Deletion Problem:
• If a parent node is deleted then the child node is automatically deleted.

• Pointers:
• Pointers are used to link the parent node with the child node and are used to
navigate between the stored data.
• Example: In the above example the 'shoes' node points to the two other nodes
'women shoes' node and 'men's shoes' node.
• Network Model
• This model is an extension of the hierarchical model.

• It was the most popular model before the relational model.

• This model is the same as the hierarchical model, the only difference is that a
record can have more than one parent.

• It replaces the hierarchical tree with a graph.


• Example: In the example below we can see that node student has two parents
i.e. CSE Department and Library. This was earlier not possible in the hierarchical
model.
• Features of a Network Model
• Ability to Merge more Relationships:
• This model has the ability to manage one-to-one relationships as well as many-
to-many relationships.

• Many paths:
• As there are more relationships so there can be more than one path to the
same record.
• This makes data access fast and simple.

• Circular Linked List: The operations on the network model are done with the
help of the circular linked list.
• Entity-Relationship Model
• Entity-Relationship Model or simply ER Model is a high-level data model
diagram.

• In this model, we represent the real-world problem in the pictorial form to


make it easy for the stakeholders to understand.

• It is also very easy for the developers to understand the system by just looking
at the ER diagram.

• We use the ER diagram as a visual tool to represent an ER Model.


• ER diagram has the following three components:
• Entities:
• Entity is a real-world thing. It can be a person, place, or even a concept.
• Example: Teachers, Students, Course, Building, Department, etc are some of the
entities of a School Management System.

• Attributes:
• An entity contains a real-world property called attribute. This is the
characteristics of that attribute.
• Example: The entity teacher has the property like teacher id, salary, age, etc.

• Relationship type:
• Relationship type tells how two entities are related.
• Example: Teacher works for a department.
• In the below diagram, the entities are Teacher and Department. The attributes
of Teacher entity are Teacher_Name, Teacher_id, Age, Salary, Mobile_Number.
• The attributes of entity Department entity are Dept_id, Dept_name. The two
entities are connected using the relationship.
• Here, each teacher works for a department.
• Features of ER Model
• Graphical Representation for Better Understanding:
• It is very easy and simple to understand so it can be used by the developers to
communicate with the end users.

• ER Diagram:
• ER diagram is used as a visual tool for representing the model.

• Database Design:
• This model helps the database designers to build the database and is widely
used in database design.
• Relational Model
• Relational Model is the most widely used model.
• In this model, the data is maintained in the form of a two-dimensional table.
• All the information is stored in the form of row and columns.
• The basic structure of a relational model is tables. So, the tables are also
called relations in the relational model.
• Example: In this example, we have an Employee table.
• Features of Relational Model
• Tuples:
• Each row in the table is called tuple.
• A row contains all the information about any instance of the object.
• In the above example, each row has all the information about any specific
individual like the first row has information about John.

• Attribute or field:
• Each column in the table is called attribute or field.
• Attributes are the property which defines the table or relation.
• In the above example, we have different attributes of the employee like Salary,
Mobile_no.
• Object-Oriented Data Model
• The real-world problems are more closely represented through the object-
oriented data model.

• In this model, both the data and relationship are present in a single structure
known as an object.

• We can store audio, video, images, etc in the database which was not possible
in the relational model.

• In this model, two or more objects are connected through links.

• We use this link to relate one object to other objects.


• This can be understood by the example given below.
• In the below example, we have two objects Employee and Department.
• All the data and relationships of each object are contained as a single unit.
• The attributes like Name, Job_title of the employee and the methods which will
be performed by that object are stored as a single object.
• The two objects are connected through a common attribute i.e the
Department_id and the communication between these two will be done with
the help of this common id.
• Mapping cardinality :
Mapping cardinality is the maximum number of relationship instances in which
an entity can participate.
• 1. One to one relationship(1:1) :
• It is represented using an arrow(⇢,⇠).

• In this ER diagram, both entities customer and driving license having an arrow
which means the entity Customer is participating in the relation “has a” in a one-
to-one fashion. It could be read as ‘Each customer has exactly one driving license
and every driving license is associated with exactly one customer.
• 2. One to many relationship (1:M) :
• This relationship is one to many because “There are some employees who
manage more than one team while there is only one manager to manage a
team”.

• The set-theoretic perspective of the ER diagram is :


• 3. Many to one relationship (M:1) :
• It is related to a one-to-many relationship but the difference is due to
perspective.

• Any number of credit cards can belong to a customer and there might be some
customers who do not have any credit card, but every credit card in a system has
to be associated with an employee(i.e. total participation). While a single credit
card can not belong to multiple customers.

• The set-theoretic perspective of the ER diagram is :


• 4. Many to many relationship (M:N) :
• Example –
A customer can buy any number of products and a product can be bought by
many customers.

• The set-theoretic perspective of the ER diagram is :


• Relation Key: These are basically the keys that are used to identify the rows
uniquely or also help in identifying tables. These are of the following types.
• Primary Key
• Candidate Key
• Super Key
• Foreign Key
• Alternate Key
• Composite Key
• 1. Candidate Key:
• The minimal set of attributes that can uniquely identify a tuple is known as a candidate key.

• It must contain unique values.


• It can contain NULL values.
• Every table must have at least a single candidate key.
• A table can have multiple candidate keys but only one primary key.
• The value of the Candidate Key is unique and may be null for a tuple.
• There can be more than one candidate key in a relationship.
• Except for the primary key, the remaining attributes are considered a candidate key. The candidate
keys are as strong as the primary key.
• 2. Primary Key:
• There can be more than one candidate key in relation out of which one can be
chosen as the primary key.
• In the EMPLOYEE table, ID can be the primary key since it is unique for each
employee. In the EMPLOYEE table, we can even select License_Number and
Passport_Number as primary keys since they are also unique.
• It is a unique key.
• It can identify only one tuple (a record) at a time.
• It has no duplicate values, it has unique values.
• It cannot be NULL.
• 3. Super Key:
• The set of attributes that can uniquely identify a tuple is known as Super Key.
• A super key is a group of single or multiple keys that identifies rows in a table.
• It supports NULL values.

• For example: In the above EMPLOYEE table, for(EMPLOEE_ID,


EMPLOYEE_NAME), the name of two employees can be the same, but their
EMPLYEE_ID can't be the same. Hence, this combination can also be a key.
• 4. Alternate Key:
• The candidate key other than the primary key is called an alternate key.
• All the keys which are not primary keys are called alternate keys.
• It is a secondary key.
• It contains two or more fields to identify two or more records.
• These values are repeated.
• Eg:- Roll no and Email is Alternate keys
• 5. Foreign Key:
• If an attribute can only take the values which are present as values of some other
attribute, it will be a foreign key to the attribute to which it refers.
• The relation which is being referenced is called referenced relation and the
corresponding attribute is called referenced attribute.
• The referenced attribute of the referenced relation should be the primary key to
it.
• It is a key it acts as a primary key in one table and it acts as
secondary key in another table.
• It combines two or more relations (tables) at a time.
• They act as a cross-reference between the tables.
• 6. Composite Key:
• Whenever a primary key consists of more than one attribute, it is known as a
composite key.
• This key is also known as Concatenated Key.
• It acts as a primary key if there is no primary key in a table
• Two or more attributes are used together to make a composite key.

• Example:

• FULLNAME + DOB can be combined


• together to access the details of a student.
• ER diagram
• ER model stands for an Entity-Relationship model.
• It is a high-level data model.
• This model is used to define the data elements and relationship for a specified
system.

• It develops a conceptual design for the database.

• It also develops a very simple and easy to design view of data.

• In ER modeling, the database structure is represented as a diagram called an


entity-relationship diagram.
• An ER diagram shows the relationship among entity sets.
• Entity
• An entity may be any object, class, person or place.
• In the ER diagram, an entity can be represented as rectangles.
• Weak Entity
• An entity that depends on another entity called a weak entity.
• The weak entity doesn't contain any key attribute of its own.
• The weak entity is represented by a double rectangle.
• Attributes
• Attributes are the properties of entities.
• Attributes are represented by means of ellipses.
• Every ellipse represents one attribute and is directly connected to its entity
(rectangle).
• If the attributes are composite, they are further divided in a tree like structure.
• Every node is then connected to its attribute.
• That is, composite attributes are represented by ellipses that are connected with
an ellipse.
• Multivalued attributes are depicted by double ellipse.
• Derived attributes are depicted by dashed ellipse.
• Relationship
• A relationship is used to describe the relation between entities.
• Diamond or rhombus is used to represent the relationship.
• Types of relationship
• a. One-to-One Relationship
• When only one instance of an entity is associated with the relationship, then it is
known as one to one relationship.
• For example, A female can marry to one male, and a male can marry to one
female.
• Types of relationship
• b. One-to-many relationship
• When only one instance of the entity on the left, and more than one instance of
an entity on the right associates with the relationship then this is known as a
one-to-many relationship.
• For example, Scientist can invent many inventions, but the invention is done by
the only specific scientist.
• Types of relationship
• c. Many-to-one relationship
• When more than one instance of the entity on the left, and only one instance of
an entity on the right associates with the relationship then it is known as a
many-to-one relationship.
• For example, Student enrolls for only one course, but a course can have many
students.
• Types of relationship
• d. Many-to-many relationship
• When more than one instance of the entity on the left, and more than one
instance of an entity on the right associates with the relationship then it is
known as a many-to-many relationship.
• For example, Employee can assign by many projects and project can have many
employees.

You might also like