r23 Dbms Record
r23 Dbms Record
Queries using Aggregate Functions (COUNT, SUM, AVG, MAX, and MIN), GROUP
BY, HAVING, and Creation and Dropping of Views.
THEORY
Aggregate functions in SQL perform calculations on a set of values and return a single
summarized result. These functions are useful in analyzing large datasets and
extracting meaningful insights.
Views in SQL
A view is a virtual table based on a SELECT query. It provides a way to store query
results without physically storing data, improving security and performance.
• Efficient Data Retrieval: Helps extract specific data quickly using optimized
queries.
• Data Integrity: Ensures constraints like PRIMARY KEY and FOREIGN KEY
maintain relationships.
• Structured Data Manipulation: Enables filtering, sorting, and aggregating
data based on conditions.
• Enhancing Performance: Using EXISTS, IN, and indexing optimizes query
execution.
These SQL features are widely used in real-world applications such as:
Advanced queries ensure efficient data processing and provide meaningful insights
from relational databases. SQL provides powerful querying capabilities that allow data
retrieval based on specific conditions. The following SQL clauses and operators are
commonly used for advanced querying:
• ANY & ALL: Used with comparison operators to compare a value with a set of
values returned by a subquery.
• IN & EXISTS: Filters records based on lists or subqueries.
• NOT EXISTS: Identifies records that do not exist in another table.
PROCEDURE
DESC Student;
Output:
+--------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| RollNo | INT | NO | PRI | NULL | |
| Name | VARCHAR(50)| NO | | NULL | |
| Age | INT | NO | | NULL | |
| Marks | INT | YES | | NULL | |
| Rank | INT | YES | | NULL | |
+--------+-------------+------+-----+---------+-------+
Output:
+--------+--------+-----+-------+------+
| RollNo | Name | Age | Marks | Rank |
+--------+--------+-----+-------+------+
| 101 | Alice | 20 | 85 | 2 |
| 102 | Bob | 22 | 90 | 1 |
| 103 | Charlie| 19 | 75 | 3 |
| 104 | David | 21 | 70 | 4 |
| 105 | Emma | 20 | 65 | 5 |
+--------+--------+-----+-------+------+
Output:
+--------+--------+
| RollNo | Name |
+--------+--------+
| 104 | David |
+--------+--------+
Output:
+--------+
| Name |
+--------+
| Bob |
| Alice |
| Charlie|
+--------+
SELECT Name FROM Student S WHERE EXISTS (
SELECT 1 FROM Student M WHERE M.RollNo = S.RollNo AND M.Marks > 80
);
Output:
+--------+
| Name |
+--------+
| Alice |
| Bob |
+--------+
Output:
+--------+
| Name |
+--------+
| Alice |
| Bob |
| Charlie|
| David |
+--------+
SELECT Name FROM Student WHERE Rank < 3
Output:
+--------+
| Name |
+--------+
| Alice |
| Bob |
+--------+
RESULT
The experiment successfully demonstrates the use of subqueries, constraints, and set
operations such as ANY, ALL, IN, EXISTS, NOT EXISTS, UNION, and INTERSECT in
SQL.
THEORY
A stored function in PL/SQL is a subprogram that returns a single value and can be
called within SQL statements. Functions enhance modularity and reusability by
performing calculations and returning values based on input parameters.
PROCEDURE
Output:
Output:
RESULT
The experiment successfully demonstrates the creation and execution of stored
functions in PL/SQL, allowing SQL queries to invoke functions directly for
calculations and performance analysis.