0% found this document useful (0 votes)
35 views24 pages

Rdbms Unit 2

Uploaded by

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

Rdbms Unit 2

Uploaded by

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

UNIT-2

DATABASE DESIGN USING ER MODEL


OVERVIEW

Entity in DBMS

Database Management System (DBMS) is an essential tool to manage data, but


do you know how important entities are in DBMS?

The role of the entity is the representation and management of data.

Entity:

An entity is referred to as an object or thing that exists in the real world. For
example, customer, car, pen, etc.

Entities are stored in the database, and they should be distinguishable, i.e., they
should be easily identifiable from the group.

For example, a group of pens that are from the same company cannot be
identified, so they are only objects, but pens with different colours become
unique and will be called an entity like a red pen, green pen, blue pen, black pen,
etc.In a group of pens, we can easily identify any pen because of its different
colours, so a pen of different colours is an entity.

For extracting data from the database, each data must be unique in its own way
so that it becomes easier to differentiate between them. Distinct and unique data
is known as an entity.

An entity has some attributes which depict the entity's characteristics. For
example, an entity "Student" has attributes such as "Student_roll_no",
"Student_name", "Student_subject", and "Student_marks".
ER (Entity Relationship)

○ 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 portrayed as a diagram called an


entity-relationship diagram.

For example, Suppose we design a school database. In this database, the


student will be an entity with attributes like address, name, id, age, etc. The
address can be another entity with attributes like city, street name, pin code, etc
and there will be a relationship between them.
Component of ER Diagram

1. Entity:

An entity may be any object, class, person or place. In the ER diagram, an entity
can be represented as rectangles.

Consider an organization as an example- manager, product, employee,


department etc. can be taken as an entity.
a. 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.

2. Attribute

The attribute is used to describe the property of an entity. Eclipse is used to


represent an attribute.

For example, id, age, contact number, name, etc. can be attributes of a student.

a. Key Attribute

The key attribute is used to represent the main characteristics of an entity. It


represents a primary key. The key attribute is represented by an ellipse with the
text underlined.
b. Composite Attribute

An attribute that composed of many other attributes is known as a composite


attribute. The composite attribute is represented by an ellipse, and those ellipses
are connected with an ellipse.
c. Multivalued Attribute

An attribute can have more than one value. These attributes are known as a
multivalued attribute. The double oval is used to represent multivalued attribute.

For example, a student can have more than one phone number.

d. Derived Attribute

An attribute that can be derived from other attribute is known as a derived


attribute. It can be represented by a dashed ellipse.

For example, A person's age changes over time and can be derived from
another attribute like Date of birth.
3. Relationship

A relationship is used to describe the relation between entities. Diamond or


rhombus is used to represent the relationship.

Types of relationship are as follows:

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.

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

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.

Cardinality in DBMS (Mapping Constraints)

DBMS

DBMS stands for Database Management System, which is a tool, or a software


used to do various operations on a Database like the Creation of the Database,
Deletion of the Database, or Updating the current Database. To simplify
processing and data querying, the most popular types of Databases currently in
use typically model their data as rows and columns in a set of tables. The data
may then be handled, updated, regulated, and structured with ease. For writing
and querying data, most Databases employ Structured Query Language (SQL).

Cardinality

Cardinality means how the entities are arranged to each other or what is the
relationship structure between entities in a relationship set. In a Database
Management System, Cardinality represents a number that denotes how many
times an entity is participating with another entity in a relationship set. The
Cardinality of DBMS is a very important attribute in representing the structure of
a Database. In a table, the number of rows or tuples represents the Cardinality.

Cardinality Ratio

Cardinality ratio is also called Cardinality Mapping, which represents the


mapping of one entity set to another entity set in a relationship set. We generally
take the example of a binary relationship set where two entities are mapped to
each other.

Cardinality is very important in the Database of various businesses. For example,


if we want to track the purchase history of each customer then we can use the
one-to-many cardinality to find the data of a specific customer. The Cardinality
model can be used in Databases by Database Managers for a variety of
purposes, but corporations often use it to evaluate customer or inventory data.

There are four types of Cardinality Mapping in Database Management Systems:

1. One to one

2. Many to one

3. One to many

4. Many to many

One to One

One to one cardinality is represented by a 1:1 symbol. In this, there is at most


one relationship from one entity to another entity. There are a lot of examples of
one-to-one cardinality in real life databases.
For example, one student can have only one student id, and one student id can
belong to only one student. So, the relationship mapping between student and
student id will be one to one cardinality mapping.

Another example is the relationship between the director of the school and the
school because one school can have a maximum of one director, and one
director can belong to only one school.

Many to One Cardinality:

In many to one cardinality mapping, from set 1, there can be multiple sets that
can make relationships with a single entity of set 2. Or we can also describe it as
from set 2, and one entity can make a relationship with more than one entity of
set 1.

One to one Cardinality is the subset of Many to one Cardinality. It can be


represented by M:1.

For example, there are multiple patients in a hospital who are served by a single
doctor, so the relationship between patients and doctors can be represented by
Many to one Cardinality.
One to Many Cardinalities:

In One-to-many cardinality mapping, from set 1, there can be a maximum single


set that can make relationships with a single or more than one entity of set 2. Or
we can also describe it as from set 2, more than one entity can make a
relationship with only one entity of set 1.

One to one cardinality is the subset of One-to-many Cardinality. It can be


represented by 1: M.

For Example, in a hospital, there can be various compounders, so the


relationship between the hospital and compounders can be mapped through
One-to-many Cardinality.
Many to Many Cardinalities:

In many, many cardinalities mapping, there can be one or more than one entity
that can associate with one or more than one entity of set 2. In the same way
from the end of set 2, one or more than one entity can make a relation with one
or more than one entity of set 1.

It is represented by M: N or N: M.

One to one cardinality, One to many cardinalities, and Many to one cardinality is
the subset of the many to many cardinalities.

For Example, in a college, multiple students can work on a single project, and a
single student can also work on multiple projects. So, the relationship between
the project and the student can be represented by many to many cardinalities.
Appropriate Mapping Cardinality

Evidently, the real-world context in which the relation set is modeled determines
the Appropriate Mapping Cardinality for a specific relation set.

○ We can combine relational tables with many involved tables if the


Cardinality is one-to-many or many-to-one.

○ One entity can be combined with a relation table if it has a one-to-one


relationship and total participation, and two entities can be combined with
their relation to form a single table if both of them have total participation.

○ We cannot mix any two tables if the Cardinality is many-to-many.Primary


Key in DBMS

○ There are certain keys in DBMS that are used for different purposes, from
which the most commonly known is the Primary Key.
○ Here, in this section, we will look at the Primary key - What it is, what is the
use of a primary key, and we will also implement some examples to
understand that how a primary key works.

What is a Primary Key


○ A Primary Key is the minimal set of attributes of a table that has the task to
uniquely identify the rows, or we can say the tuples of the given particular
table.

○ A primary key of a relation is one of the possible candidate keys which the
database designer thinks it's primary. It may be selected for convenience,
performance and many other reasons. The choice of the possible primary
key from the candidate keys depend upon the following conditions.

Minimal: The primary key should be composed of the minimum number of


attributes that satisfy unique occurrences of the tuples. So if one candidate key is
formed using two attributes and another using a single attribute then the one with
the single attribute key should be chosen as the primary key.

Accessible: The primary key used should be accessible by anyone who wants
to use it. The user must easily insert, access or delete a tuple using it.

NON NULL Value: The primary key must have a non-null value for each tuple of
the relation, which is required for the identification of the tuple.

Time Variant: The values of the primary key must not change or become null
during the time of a relation.

Unique: The value of the primary key must not be duplicated in any of the tuples
of a relation.
Syntax for creating primary key constraint:

The primary key constraint can be defined at the column level or table
level.

At column level:

1. <column_name><datatype> Primary key;

At table level:

1. Primary key(<column_name1>[,column_name>]....);

Properties of a Primary Key:

○ A relation can contain only one primary key.

○ A primary key may be composed of a single attribute known as single


primary key or more than one attribute known as composite key.

○ A primary key is the minimum super key.

○ The data values for the primary key attribute should not be null.

○ Attributes which are part of a primary key are known as Prime attributes.

○ Primary key is always chosen from the possible candidate keys.

○ If the primary key is made of more than one attribute then those attributes
are irreducible.

○ We use the convention that the attribute that form primary key of relation is
underlined.

○ Primary key cannot contain duplicate values.

○ Columns that are defined as LONG or LONG RAW cannot be part of a


primary key.
Use of Primary Key

As defined above, a primary key is used to uniquely identify the rows of a table.
Thus, a row that needs to be uniquely identified, the key constraint is set as the
Primary key to that particular field. A primary key can never have a NULL value
because the use of the primary key is to identify a value uniquely, but if no value
will be there, how could it sustain. Thus, the field set with the primary key
constraint cannot be NULL. Also, it all depends on the user that the user can add
or delete the key if applied.

Reduction of ER diagram to Table

The database can be represented using the notations, and these notations can
be reduced to a collection of tables.

In the database, every entity set or relationship set can be represented in tabular
form.
The ER diagram is given below:

There are some points for converting the ER diagram to the table

In the given ER diagram, LECTURE, STUDENT, SUBJECT and COURSE forms


individual tables.

○ All single-valued attribute becomes a column for the table.

In the STUDENT entity, STUDENT_NAME and STUDENT_ID form the column of


STUDENT table. Similarly, COURSE_NAME and COURSE_ID form the column
of COURSE table and so on.

○ A key attribute of the entity type represented by the primary key.

In the given ER diagram, COURSE_ID, STUDENT_ID, SUBJECT_ID, and


LECTURE_ID are the key attribute of the entity.
○ The multivalued attribute is represented by a separate table.In the
student table, a hobby is a multivalued attribute. So it is not possible to
represent multiple values in a single column of STUDENT table. Hence we
create a table STUD_HOBBY with column name STUDENT_ID and
HOBBY. Using both the column, we create a composite key.

○ Composite attribute represented by components.

In the given ER diagram, student address is a composite attribute. It contains


CITY, PIN, DOOR#, STREET, and STATE. In the STUDENT table, these
attributes can merge as an individual column.

○ Derived attributes are not considered in the table.

In the STUDENT table, Age is the derived attribute. It can be calculated at any
point of time by calculating the difference between current date and Date of Birth.

Using these rules, you can convert the ER diagram to tables and columns and
assign the mapping between the tables. Table structure for the given ER diagram
is as below:
Figure: Table structure

Features of ER model

The features of the ER model are as follows −

It is widely used to develop the initial design of the database.


It provides a collection of basic concepts that can be easily implemented in
a database system.
It describes data as a set of entities, attributes, and relationships.
It provides the graphical view of the database design.
Advantages

The advantages of the ER model are as follows −

It is easy to create and understand.


It is very simple because if you know the relationship between attributes
and entities, you can easily draw it.
It is a tool for effective communication for database designers.
It can be easily converted into a Relational Model

Disadvantages

The disadvantages of the ER model are as follows −

It is not suitable for the semi-structured or unstructured data set.


It is difficult to show data manipulation.

Notation of ER diagram

Database can be represented using the notations. In ER diagram, many


notations are used to express the cardinality. These notations are as
follows:
Components of ER Diagram in dbms
As above image describes,

■ Rectangle – It represents entity in the ER Model.


■ Ellipse – It represents attribute in the ER Model.
■ Diamond – It represents relationship between entity and attribute.
■ Line – It links attribute(s) to entity set(s) and entity set(s) to
relationship set(s).
■ Doubles Ellipses – It represents multivalued attributes.
■ Dashed Ellipses – It denotes derived attributes.
■ Double lines – It indicates total participation of an entity in a
relationship set.
■ Double Rectangle – It represents weak entity set.
■ Double Diamonds – It represents weak relationships.
■ Multiple ellipses connected to single ellipse using lines – It represents
composite attribute
■ Ellipse with line inside it – It represents single values attributes

Connectivity of a Relationship –

It means how many instances of one entity type are linked with how many entity
of another entity set. Different types of connectivity of a relationship are –

(A) one-to-one relationship – If the relationship is one-to-one i.e. each customer


has one account and each account belongs to one customer, then this is
represented as follows. –
Type – 1

(B) many-to-one relationship – If this relationship is many-to-one, i.e. many


customers can share one account then this is represented as follows.

Type – 2

(C) one-to-many relationship – If the relationship is one-to-many, i.e. one


customer may have any number of accounts, but one account belongs to only
one customer then this cardinality is represented as –
Type – 3

(D) many-to-many relationship – If relationship is many-to-many, i.e. one


customer may have any number of accounts and one account can be shared by
any number of customers, then this is represented as follows.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy