MYSQL LAB Manual DBMS Final (1) Removed
MYSQL LAB Manual DBMS Final (1) Removed
MYSQL LAB Manual DBMS Final (1) Removed
LIST OF EXPERIMENTS
11 PL/SQL Functions
12 PL/SQL Cursors
14 PL/SQL Trigger
Theory:- MySQL has many built-in functions.This reference contains string, numeric,date, and
some advanced functions in MySQL.
1. UPPER():-
2. LOWER():-
QUERY:-
CONCAT():-
QUERY:-
SELECT id,NAME, CONCAT(name ,percentage) AS CONCAT FROM
employee;
1.CURRENT_DATE():-
QUERY:-
SELECT CURRENT_DATE();
2. NOW():-
QUERY:-
SELECT NOW();
3.DATE():-QUERY:-
SELECT DATE("2022-04-24 23:48:15");
TIME FUNCTIONS:-
1.Current_time():-
QUERY:-
SELECT current_time();
2 Current_timestamp():-
QUERY:-
SELECT current_timestamp();
3. localtime():-
QUERY:-
SELECT localtime();
To Execute Aggregate Functions.: SQL aggregation function is used to perform the calculations on
multiple rows of a single column of a table. It returns a single value.It is also used to summarize the data.
1. COUNT FUNCTION: COUNT function is used to Count the number of rows in a database
table. It can workon both numeric and non-numeric data types.
QUERY:
2. SUM Function: Sum function is used to calculate the sum of all selected columns.
It works onnumeric fields only.
QUERY:-
3. AVG function: The AVG function is used to calculate the average value of the numeric
type.
QUERY:-
QUERY:-
5. MIN Function: MIN function is used to find the minimum value of a certain column. This
functiondetermines the smallest value of all selected values of a column.
QUERY:-
SELECT MIN(percentage) FROM employee_table;
RESULT: The inbuilt function commands in RDBMS are implemented successfully and output is verified.
Exp No:-5
Theory:-
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.
Stu_Name
Col_Id Col_Name
Stu_Id Stu_addr
Study
Student In College
Exp No:-6
Nested Queries on sample exercise
Aim:- To Execute Subqueries
Theory:-A subquery in MySQL is a query, which is nested into another SQL query and embedded with SELECT,
INSERT, UPDATE or DELETE statement along with the various operators. We can also nest the subquery with
another subquery. Asubquery is known as the inner query, and the query that contains subquery is known as the outer
query. The inner query executed first gives the result to the outer query, and then the main/outer query will be
performed. MySQL allows us to use subquery anywhere, but it must be closed within parenthesis. All subquery forms
and operationssupported by the SQL standard will be supported in MySQL also.
QUERY:-
QUERY 1:-
SELECT * from department where id
IN(SELECT id from department where salary>12000);
QUERY 1:-
SELECT * from department where salary>
(SELECT AVG(salary) from department);
Find the name and salary of the employee with maximum salary:-
CREATING TABLE
CREATE TABLE department(id
INT,
name varchar(100),
gender
varchar(50),city
varchar(20), salary
int
);
QUERY:-
SELECT * from department where id
IN(SELECT max(salary) from department);
Find the count of employees for each job so that at least two of the employees had salary greater than 10000:-
QUERY:-
SELECT count(name) AS COUNT from department
where name=(select count(salary)>10000 from department)
RESULT: The program for nested queries in RDBMS are implemented successfully and output is verified.
Exp No:-7
Join Queries
Theory: MySQL JOINS are used with SELECT statement. It is used to retrieve data from multiple tables. It is performed
whenever you need to fetch records from two or more tables.
MySQL Inner JOIN (Simple Join): The MySQL INNER JOIN is used to return all rows from multiple tables where the
join condition is satisfied. It is the most common type of join.
QUERY:-
QUERY:-
SQL FULL OUTER JOIN Keyword:The FULL OUTER JOIN keyword returns all records when there is a match in left
(table1) or right (table2) table records.
QUERY:-
SELECT * FROM personalLEFT JOIN city
ON personal.city=city.cid UNIONSELECT * FROM personal RIGHT JOIN city
ON personal.city=city.cid;
SQL CROSS JOIN Keyword: The CROSS JOIN keyword returns all records from both tables (table1 and table2).
QUERY:
Theory:- SQL supports few Set operations which can be performed on the table data. These are used to get meaningful
results from data stored in the table, under different special conditions.
SET OPERATORS:-
Union
Union all
Intersect
Minus
Union:-Query:-
SELECT *from student1UNION
SELECT * from students
Union All:-
FOR EXECUTION
SELECT DISTINCT Id FROM tab1INNER JOIN tab2 USING (Id);
MINUS:-Query:
FOR EXECUTION
SELECT
id FROM
t1
LEFT JOIN
t2 USING (id)WHERE
t2.id IS NULL;
VIEWS:-
Theory:-
A view contains rows and columns, just like a real table. The fields in a view are fields from one or more real tables in the
database.
You can add SQL statements and functions to a view and present the data as if thedata were coming from one single table.
QUERY:-
ON s.id= c.cid;
QUERY:-
ALTER IN VIEWSQUERY:-
ALTER VIEW dataAS
SELECT * FROM student_tableINNER JOIN City
ON student_table.city=City.cidWHERE age>22;
SELECT *from data;
RESULT: The program for Set Operators & Views in RDBMS is implemented successfully and output is
verified.
Exp No:-9
Conditional & Iterative Statements
Theory:- A program that supports a user interface may run a main loop that waits for, and then
processes, user keystrokes (this doesn’t apply to stored programs, however).Many mathematical
algorithms can be implemented only by loops in computer programs.When processing a file, a
program may loop through each record in the file and perform computations.A database program
may loop through the rows returned by a SELECT statement.
QUERY:
a) Conditional Statement
FOR EXECUTION
SELECT
customerNum
ber,
creditLimit
FROM
custo
mers
WHERE
creditLimit >
50000ORDER BY
creditLimit DESC;
Iterative Statement
CREATE TABLE calendars(
id INT AUTO_INCREMENT,
fulldate DATE UNIQUE, day TINYINT NOT NULL,
month TINYINT NOT NULL,
quarter TINYINT NOT NULL,year INT NOT NULL, PRIMARY KEY(id)
);
FOR CREATING PROCEDURE
DELIMITER $$
CREATE PROCEDURE InsertCalendar(dtDATE)
BEGIN
INSERT INTO calendars(fulldate,
day, month, quarter,year
) VALUES(
dt,
EXTRACT(DAY FROM dt), EXTRACT(MONTH FROM dt), EXTRACT(QUARTER FROM dt),EXTRACT(YEAR FROM dt)
);
END$$ DELIMITER ;
DELIMITER $$
CREATE PROCEDURE LoadCalendars(startDate DATE,
day INT
) BEGIN
DECLARE counter INT DEFAULT 1;
DECLARE dt DATE DEFAULT
startDate;
WHILE counter <= day DO CALL InsertCalendar(dt); SET counter = counter + 1;SET dt =
DATE_ADD(dt,INTERVAL 1 day);END WHILE;
END$$ DELIMITER ;
Theory:- A procedure (often called a stored procedure) is a collection of pre- compiled SQL statements stored inside
the database. It is a subroutine or a subprogram in the regular computing language. A procedure always contains a
name, parameter lists, and SQL statements. We can invoke the procedures by using triggers, other procedures and
applications such as Java, Python, PHP, etc. It was first introduced in MySQL version 5. Presently, it can be supported
by almost all relationaldatabase systems.
If we consider the enterprise application, we always need to perform specific tasks such as database cleanup,
processing payroll, and many more on the database regularly. Such tasks involve multiple SQL statements for
executing each task. This process might easy if we group these tasks into a single task. We can fulfill this requirement
in MySQL by creating a stored procedure in our database.
Query:-
create table film(rating int ,name varchar(20),release_date int);insert into film values(4,'tomandJerry',90);
insert into film values(5,'harrypotter',21); insert into film values(2,'jamesBond',85); insert into film
values(3,'jumanji',22);
DELIMITER //
CREATE PROCEDURE sp_GetMovies()BEGIN
select rating,name,release_date from film;END //
DELIMITER ;
CALL sp_GetMovies();
RESULT: The program for PL/SQL Procedures on sample exercise in RDBMS is implemented successfully and output
isverify..
Exp No:-11
PL/SQL Functions
QUERY
CREATING FUNCTION
DELIMITER //
CREATE FUNCTION no_of_years(date1 date) RETURNS int DETERMINISTICBEGIN
DECLARE date2 DATE; Select current_date()into date2; RETURN year(date2)-year(date1); END //
DELIMITER ;
CALLING FUNCTION
Select emp_id, fname, lname, no_of_years(start_date) as 'years' from employee;
OUTPUT:-
RESULT: The program for PL/SQL PL/SQL Functions in RDBMS is implemented successfully and output is verified.
Exp No:-12
PL/SQL Cursors
Aim:- To Execute Cursors in MySql
Theory:- A cursor allows you to iterate a set of rows returned by a query and processeach row individually. MySQL
cursor is read-only, non-scrollable and asensitive. Read-only: you cannot update data in the underlying table through
the cursor.
QUERY:-
RESULT: The program for PL/SQL Cursors in RDBMS is implemented successfully and output is verified.
Exp No:-13
PL/SQL Exception Handling
Theory:-When an error occurs inside a stored procedure, it is important to handle it appropriately, such as
continuing or exiting the current code block’s execution, and issuing a meaningful error message.MySQL
provides an easy way to define handlers that handle from general conditions such as warnings or exceptions to
specific conditions e.g., specific error codes.
QUERY:-
FROM SupplierProducts
RESULT: The program for PL/SQL EXCEPTION handling in RDBMS is implemented successfully and
output is verified.
Exp No:-14
PL/SQL Trigger
Theory:- A trigger in MySQL is a set of SQL statements that reside in a system catalog. It is a special type of
stored procedure that is invoked automatically in response to an event. Each trigger is associated with a table,
which is activated on anyDML statement such as INSERT, UPDATE, or DELETE.
A trigger is called a special procedure because it cannot be called directly like a stored procedure. The main
difference between the trigger and procedure is that a trigger is called automatically when a data modification
event is made against a table. In contrast, a stored procedure must be called explicitly.
QUERY:-
AIM –Frame and execute all queries for a project: Home renting system database
INTRODUCTION:-The Home Rental System is Searching in Based on the Apartment House for rent in
metropolitan cities. The Home Rental System is Basedon the Owners and the Customers. The Owner is updated
on the Apartment details, and rent details. The Customer is details about the Room space, Room rent and the
Address Details also.
PROBLEM STATEMENT
There is no properly allocate home and the system is not easily arranges according to their user interest. And
also the home rental management system almost is done through the manual system.
The administrative system doesn’t have the facility to make home rental
management system through online and the most time the work done through illegal intermediate personwithout
awareness of the administrative and this make more complex and more cost to find home for the customer. This
leads to customer in to more trouble, cost, dishonest and time wastage.
OBJECTIVE
The main objective of the system is to develop online home rental
managementsystem for wolkite city
Specific objectives
In order to attain the general objective, the following are the list of specific objectives:
• To facilitate home record keeping for who wants home and for
administrativemanagement system.
• Prepare an online home rental system for the home finders
• To reduce the travel costs and other unnecessary expenses of the buyer.
• Reduce the role of the broker, thus, providing protection from frauds
related topapers.
MODULES
• Tenant
• Owner
• Contract
• Payment
OPERATION:
First will be the login page where the User will login using their ID and Password.
Next the user will enter the details like the requirements of the house he needsand contact details
The other ebd user who wants to rent their house can also give their details
He can also search the houses available in a particular area.
Whoever has the required spcifications of the house can contact using the details provided.
There is also a chatting option if they want to communicate with each other. There is also an option of video calling.
After providing the details in the website, a contract will be generated which they can download.
OUTPUT:-
a) Cursor Output
b) Exception Handling
RESULT: The program for Frame and Execute PL/SQL Cursor & ExceptionalHandling in RDBMS is implemented successfully
and output is verified.