Dbms

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 12

DATABASE

MANAGNMET
SYSTEM
SUBMITTED BY:
NAME: AROOJ FATIMA
ROLL NO: 21:F1:136
SEMESTER : 2ND
SESSEION: ADP (IT)

SUBMITTED TO:
MAAM FAREEHA ARSHAD
Table of Contents
Aggregate Functions in DBMS:................................................................................................................3
TYPES OF AGREGATE FUNCTION....................................................................................................3
AVG Function........................................................................................................................................3
COUNT Function..................................................................................................................................3
SUM Function........................................................................................................................................3
MAX Function.......................................................................................................................................4
MIN Function........................................................................................................................................4
SQL aggregate functions syntax...............................................................................................................4
aggregate function examples.....................................................................................................................4
COUNT function example....................................................................................................................4
AVG function example..........................................................................................................................5
SUM function example..........................................................................................................................5
MIN function example...........................................................................................................................6
MAX function example.........................................................................................................................6
Uses of aggregation in DBMS...................................................................................................................7
Many trivial entities:.............................................................................................................................7
One trivial entity:..................................................................................................................................7
Inapplicable entity-model relationship:...............................................................................................7
Process flow for aggregation in DBMS....................................................................................................7
The following are the main types of relationships in an ER model:..................................................8
One-to-one:.........................................................................................................................................8
One-to-many:.....................................................................................................................................8
Many-to-one:......................................................................................................................................8
Many-to-many:..................................................................................................................................8
Example of aggregation in DBMS............................................................................................................8
What are the data aggregation techniques in DBMS?............................................................................9
In-Network Aggregation.......................................................................................................................9
Tree-Based Approach............................................................................................................................9
Multi-Path Approach............................................................................................................................9
Cluster-Based Approach.......................................................................................................................9
Why is Aggregation important in DBMS?...............................................................................................9
Example to Implement in DBMS.............................................................................................................9
Significance of Aggregation in DBMS....................................................................................................10
Conclusion................................................................................................................................................11
Aggregate Functions in DBMS:
Aggregate functions are those functions in the DBMS which takes the values of multiple rows of
a single column and then form a single value by using a query. These functions allow the user to
summarizing the data. These functions ignore the NULL values except the count function.

TYPES OF AGREGATE FUNCTION


1. AVG
2. COUNT
3. SUM
4. MIN
5. MAX

AVG Function
This function takes the values from the given
column and then returns the average of the
values. This function works only on the
datatypes, which are specified as numeric in the
table.
Let's take an example, which describes to you how to use the AVG function in SQL. Suppose we
want to calculate the average salary from the Employee Details table, then we have to type the
following query:
Select AVG (Employee salary) from Employee Details;

COUNT Function
This aggregate function returns the total number of values in the specified column. This function
can work on any type of data, i.e., numeric as well as non-numeric. This function does not count
the NULL values. If we want to count all the rows with NULL values, then we have to use the
Count (*) function.
Let's take an example, which describes to us how to use the COUNT function in SQL. Suppose a
user wants to count the number of employees in the Employee Details table, then we have to
type the following query:
Select Count (Employee ID) from Employee Details;

SUM Function
This aggregate function sums all the non-NULL values of the given column. Like the AVG
function, this function also works only on the numeric data.
Let's take an example, which describes to you how to use the SUM function in SQL. Suppose a
user wants to find the sum of salary from the Employee Details table, then we have to type the
following query:
Select SUM (Employee salary) from Employee Details;

MAX Function
This function returns the value, which is maximum from the specified column.
Let's take an example, which describes to you how to use the MAX function in SQL. Suppose
we want to find the maximum price of the Cars Price column from the Cars table, then we have
to type the following query:
Select MAX (Cars Price) from Cars;

MIN Function
This function returns the value, which is minimum from the specified column.
Let's take an example, which describes to you how to use the MIN function in SQL. Suppose we
want to find the minimum price of the Bikes Price column from the Bikes table, then we have to
type the following query:
Select MIN (Bikes Price) from Bikes;

SQL aggregate functions syntax


To call an aggregate function, you use the following syntax:
aggregate function (DISTINCT | ALL expression)
Let’s examine the syntax above in greater detail:
 First, specify an aggregate function that you want to use
e.g., MIN, MAX, AVG, SUM or COUNT.
 Second, put DISTINCT or ALL modifier followed by an expression inside parentheses. If
you explicitly use the DISTINCT modifier, the aggregate function ignores duplicate
values and only consider the unique values. If you use the ALL modifier, the aggregate
function uses all values for calculation or evaluation. The ALL modifier is used by
default if you do not specify any modifier explicitly.

aggregate function examples


Let’s take a look some examples of using SQL aggregate functions.

COUNT function example


To get the number of products in the products table, you use the COUNT function as follows:
SELECT
COUNT (*)
FROM
products;

More information on the COUNT function.

AVG function example


To calculate the average units in stock of the products, you use the AVG function as follows:
SELECT
AVG (units in stock)
FROM
products;

To calculate units in stock by product category, you use the AVG function with the  GROUP
BY clause as follows:
SELECT
Category id, AVG (units in stock)
FROM
products
GROUP BY category id;

More information on AVG function.

SUM function example


To calculate the sum of units in stock by product category, you use the SUM function with the
GROUP BY clause as the following query:
SELECT
Category id, SUM (units in stock)
FROM
products
GROUP BY category id;

Check it out the SUM function tutorial for more information on how to use the SUM function.

MIN function example


To get the minimum units in stock of products in the products table, you use the MIN function as
follows:
SELECT
MIN (units in stock)
FROM
products;

More information on the MIN function.

MAX function example


To get the maximum units in stock of products in the products table, you use the MAX function
as shown in the following query:
SELECT
MAX (units in stock)
FROM
products;

Check it out the MAX function tutorial for more information.


In this tutorial, we have introduced you to the SQL aggregate functions including the most
commonly used functions: AVG, COUNT, MIN, MAX, and SUM.

Uses of aggregation in DBMS


Aggregation is used when the DBMS has the following characteristics.

Many trivial entities:


A DBMS may consist of many entities that are not significant enough to provide meaningful
information. In such a case, the trivial entities can be combined into one complex entity through
aggregation. For example, many trivial entities called rooms can be combined to form a single
entity called hotel.

One trivial entity:


Aggregation is also needed if a DBMS has a single trivial entity that should be used for multiple
operations. In this case, the trivial entity is used to form relationships with other entities. This
may lead to many aggregation entities depending on the operations required. For example, an
employee in an organization may be given an insurance policy that covers his dependents. The
entity dependents is a trivial entity because it cannot exist without the entity employee.

Inapplicable entity-model relationship:


The entity-model relationship cannot be applied to certain entities within the system. These
specific entities can be combined with other entities to allow the application of the entity-model
relationship in the entire system. This ensures that all the entities in the system are utilized. For
example, the entity-model relationship for students can only be applied if students enroll in a
class. The entity grade can only be formed if the relationship enroll exists.

Process flow for aggregation in


DBMS
Aggregation in DBMS can be explained using the
entity-relationship model (ER model). This is a
conceptual diagram that represents the structure of a
database and its components. It contains the
relationships, attributes, and entities in a DBMS.
This is similar to the columns, rows, and tables in a
database.
The following are the main types of
relationships in an ER model:
One-to-one:
Here, the trivial entity forms a relationship with only
one other entity. For example, one employee can work
in only one department of an organization.

One-to-many:
In this relationship, one entity forms a relationship
with multiple entities. For example, an employee can work in multiple departments within the
same organization.

Many-to-one:
Here, multiple entities in a certain entity set can form a relationship with only one entity. For
example, many employees can work in only one department.

Many-to-many:
In this category, multiple entities from a certain entity set, that can form a relationship with
many entities from another entity set. For example, many employees can work in multiple
departments within the same organization.
In this ER model, A, B, and C represent entities. A and B should be combined into a single
complex entity. R1 is the relationship that is formed after A and B are linked. R1 needs to form a
relationship with other entities for other DBMS operations to be successful.
This operation generates a new relationship (R2). R2 is linked to another entity C to enhance its
functionality. This entity is also formed through aggregation.

Example of aggregation in DBMS


Let’s assume that there is a patient who has visited a doctor in the hospital to seek treatment for a
certain type of illness. The following diagram shows the process flow for aggregation in the
hospital.
We will follow the simple ER model described above. In the diagram above, there are three
entities: patient history, the doctor, and the patient. Filing and diagnosis represent relationships.
The doctor performs a diagnosis on the patient.
The database stores data regarding this diagnosis and any other patient data. Filing is required to
make it easier for the doctor to retrieve the patient’s information in the future.
In this example, the patient cannot work on his own. He has to form a relationship with the
doctor to get a diagnosis. The doctor also cannot perform a diagnosis without the patient. In the
future, the doctor will need data about the patient’s history, that will require him to collect it
from a filing system.
The last entity (patient’s history) ensures that the entire system is functional. Getting the
patient’s history cannot be done without a diagnosis from the doctor and a filing system.

What are the data aggregation techniques in DBMS?


We have mentioned different data aggregation techniques in detail below:

In-Network Aggregation
It is a general procedure where the information is gathered and routed using a multi-hop network.
This impressive technique is the cornerstone of the database management system.

 Tree-Based Approach
The Aggregation from developing an aggregation tree is defined with the help of a tree-based
approach. It is a very important technique for performing database management procedures
brilliantly.

 Multi-Path Approach
The partially aggregated data is transferred to a particular parent mode during the multi-path
approach. All the nodes are sent to many different inputs in this type of Aggregation.

Cluster-Based Approach
This technique is utilized for collating a great sort of data on the complete network. The cluster-
based approach is equipped with a cluster head chosen from various cluster members.

Why is Aggregation important in DBMS?


The main motive of Aggregation is to summarize the data results for database management. So,
let’s have a look at what major jobs are performed by Aggregation in DBMS below:
 It is very helpful for maintaining the collection, processing, and presentation of data
making this tool an essential component of the database management system.
 Aggregation assists in briefing data from various resources to boost the value of
information available in it.
 It is useful for finding the origin of data and creating an audit trail.
 This technique works in situations where the entry model relationship can’t be applied
adequately.
 It ensures all the entities in the database management system are utilized according to
their full potential.
Example to Implement in DBMS
Let us see an example to help in understanding the Aggregation method on the ER model of a
Database Management System. The below model
shows the same,

This Entity Relationship diagram consists of three


entities, the Patient, the Doctor, and Patient History.
It also has two relationship boxes, they are, the
Diagnosis, Filing. In real life, when the patient visits
the doctor, a diagnosis will be made. The data on the
patient, the doctor and the diagnosis will be stored
in the database. But there will be no future use for
these data if that is stored individually. Moreover,
when these data are required in the future, it is going
to be a tedious job and/or not practically possible to query each and every record that is required.
This brings up the need to organize the data of the Patient, the Doctor, and the diagnosis relating
both the Patient and the Doctor entities. This is subjected to further Aggregation by applying the
Filing operation, as Filing can make it easy to fetch the contents whenever the requirement
arises. Now we need an entity to hold this Aggregation operation, that is, Patient History Entity.
In the diagram, it shows the Patient and the Doctor are connected to the diagnosis operation.
Diagnosis is then connected to the Filing operation that represents the Aggregation function.
Filing is then connected to the newly created entity, Patient History. By introducing the
Aggregation process using the Filing operation and Patient History Entity, the ER diagram
appears to be more meaningful. This can now be used for any and all the future upgrades, and it
provides scalability to the Database Management System.

Significance of Aggregation in DBMS


Aggregation on the ER Model is one of the most crucial concepts in the Database Management
System. Below are the important factors for Aggregation in DBMS,
 In a table where one or more entities does not make sense when used alone, the entity
holds data that can be just stored and never can function on its own, it is going to occupy
space in the database without any potential use for the In this situation, Aggregation can
be applied so that the idle entity can work in relationship with any other entity from the
system.
 When the Database Management System is used for Analysis and Reporting processes,
first the Database structuring process will be When the Multidimensional structuring or
the Relational Structuring process is to be applied, all the entities are expected to be
functional and in-scope for any future operation, without any exception. In such cases,
unused entities can be passed through the Aggregation method, in order to keep it
relational with other entities in the system.
 The Aggregation method is applied to create a relationship between an entity and the
other entities of the same level, and the resulting artifact is aggregated further into a
higher level This helps in identifying the entity formed as a result of Aggregation in the
hierarchical Entity Relationship system.

Conclusion
Aggregation of Entities in the Database Management System corresponds to a connection
between two entities that are theoretically at the same hierarchical level in the ER model. The
relationship created between the entities can also be represented in the ER model as ‘has-a,’ ‘is-
a’ or ‘is-part-of’ relationships, which can have any type of entities from the Entity-Relationship
tree. Aggregation does not characterize any alteration on the flow of navigation through the
hierarchical ER model, or the relationship pattern in the ER model.

You might also like