DBMS Manual4
DBMS Manual4
B.E. Semester 3
(Information & Communication Technology)
Place: __________
Date:
Main motto of any laboratory/practical/field work is for enhancing required skills as well as
creating ability amongst students to solve real time problem by developing relevant
competencies in psychomotor domain. By keeping in view, GTU has designed competency
focused outcome-based curriculum for engineering degree programs where sufficient weightage
is given to practical work. It shows importance of enhancement of skills amongst the students
and it pays attention to utilize every second of time allotted for practical amongst students,
instructors and faculty members to achieve relevant outcomes by performing the experiments
rather than having merely study type experiments. It is must for effective implementation of
competency focused outcome-based curriculum that every practical is keenly designed to serve
as a tool to develop and enhance relevant competency required by the various industry among
every student. These psychomotor skills are very difficult to develop through traditional chalk
and board content delivery method in the classroom. Accordingly, this lab manual is designed
to focus on the industry defined relevant outcomes, rather than old practice of conducting
practical to prove concept and theory.
By using this lab manual students can go through the relevant theory and procedure in advance
before the actual performance which creates an interest and students can have basic idea prior to
performance. This in turn enhances pre-determined outcomes amongst students. Each
experiment in this manual begins with competency, industry relevant skills, course outcomes as
well as practical outcomes (objectives). The students will also achieve safety and necessary
precautions to be taken while performing practical.
This manual also provides guidelines to faculty members to facilitate student centric lab
activities through each experiment by arranging and managing necessary resources in order that
the students follow the procedures with required safety and necessary precautions to achieve the
outcomes. It also gives an idea that how students will be assessed by providing rubrics.
Database Management System is a core subject of Computer Science & Engineering-Data Science
course. Database is an integral part of real-life application system. The course will enable student
understand the different issues involved in the design and implementation of a database system.
Student will learn the physical and logical database designs, database modeling, relational,
hierarchical, and network models. Student will learn to use data manipulation language to query,
update, and manage a database. Student will understand essential DBMS concepts such as:
database security, integrity, concurrency, storage strategies etc. The students will get the hands-on
practice of using SQL and PL/SQL concepts.
Utmost care has been taken while preparing this lab manual however always there is chances of
improvement. Therefore, we welcome constructive suggestions for improvement and removal
of errors if any.
Database Management System (3130703)
DTE’s Vision
Institute’s Vision
Institute’s Mission
Department’s Vision
▪ The department aims to create an ecosystem that fosters the growth of socially
responsible and technically adept information and communication technology engineers,
innovators and entrepreneurs capable of meeting the evolving industrial and societal
requirements.
Department’s Mission
▪ Engage in creating, testing, and improving Information and Communication skills for
human benefit and advancing technology.
▪ Work independently and as a team leader, continuously updating knowledge through
various educational resources.
▪ Become a skilled specialist in Information and Communication Technology, solving
industry problems with innovative solutions.
▪ Demonstrate professionalism, collaboration, leadership, lifelong learning, ethical
application of computing skills, and pursue advanced education for research-oriented
activities.
1. Teacher should provide the guideline with demonstration of practical to the students
with all features.
2. Teacher shall explain basic concepts/theory related to the experiment to the students
before starting of each practical
3. Involve all the students in performance of each experiment.
4. Teacher is expected to share the skills and competencies to be developed in the
students and ensure that the respective skills and competencies are developed in the
students after the completion of the experimentation.
5. Teachers should give opportunity to students for hands-on experience after the
demonstration.
6. Teacher may provide additional knowledge and skills to the students even though not
covered in the manual but are expected from the students by concerned industry.
7. Give practical assignment and assess the performance of students based on task
assigned to check whether it is as per the instructions or not.
8. Teacher is expected to refer complete curriculum of the course and follow the
guidelines for implementation.
1. Students are expected to carefully listen to all the theory classes delivered by the faculty
members and understand the COs, content of the course, teaching and examination
scheme, skill set to be developed etc.
2. Student should develop a habit of submitting the experimentation work as per the schedule
and s/he should be well prepared for the same.
Index
(Progressive Assessment Sheet)
Sr. Objective(s) of Experiment Pa Date Date Assess Sign. Rem
No. ge of of ment of arks
No perfo subm Marks Teach
. rman ission er with
ce date
10.
To Study Transaction control commands & PL/SQL.
Database Management System (3130703)
Experiment No: 1
Date:
Explanation:
(a)Create a table ACCOUNT with column account number, name, city, balance, loan
taken.
(b)Create a LOAN table with column loan number, account number, loan amount,
interest rate, loan date and remaining loan.
(A) Account
acc_no Name City Balance loan_taken
(B) Loan
loan_no acc_no loan_amt Interest_ Loan_date Remaining
rate _loan
L001 A001 100000 7 1-jan-20 75000
Retrieve data from above tables using Data SQL command- “Select”
Table: ACCOUNT
(a)Update the column balance for all the account holders. (Multiply the balance by 2 for each
account holders)
Query:-
UPDATE Account
SET Balance = Balance * 2;
O/P:-
Query:-
DELETE FROM Account
WHERE acc_no = 'A004';
O/P:-
Database Management System (3130703)
Table: LOAN
(a)For each loan holders Add 100000 Rs. Amount into the column loan_amt.
QUERY:-
UPDATE Loan
SET loan_amt = loan_amt + 100000;
O/P:-
QUERY:-
UPDATE Loan
SET Interest_rate = Interest_rate + 2;
O/P:-
(c)Display only those records where loan holder taken a loan in month of January
QUERY:-
SELECT* FROM Loan
WHERE MONTH(Loan_date)=1;
O/P:-
Database Management System (3130703)
Rubrics 1 2 3 4 5 Total
Marks
Database Management System (3130703)
Experiment No: 2
Date:
Explanation:
(a)Create table SalesPeople where Snumvarchar2(4) P.K(first letter should start with S) ,
Sname varchar2(20) NOT NULL,City Varchar2(15),Mobile_No Number(10).
(b)Create table Customer where cnum varchar2(4) P.K(first letter should start with C),
Cname varchar2(20) NOT NULL,city varchar2(20),Rating number(3) DEFAULT 10,Snum
number(4) F.K (where snum refers salespeople table)
Observations:
(a)Create table SalesPeople where Snum varchar2(4) P.K(first letter should start with S) ,
Sname varchar2(20) NOT NULL,City Varchar2(15),Mobile_No Number(10).
Query:
CREATE TABLE SalesPeople (
Snum VARCHAR2(4) PRIMARY KEY CHECK (Snum LIKE 'S%'),
Database Management System (3130703)
O/P:
(b)Create table Customer where cnum varchar2(4) P.K(first letter should start with C),
Cname varchar2(20) NOT NULL,city varchar2(20),Rating number(3) DEFAULT 10,Snum
number(4) F.K (where snum refers salespeople table)
Query:
CREATE TABLE Customer (
cnum VARCHAR2(4) PRIMARY KEY CHECK (cnum LIKE 'C%'),
Cname VARCHAR2(20) NOT NULL,
city VARCHAR2(20),
Rating NUMBER(3) DEFAULT 10,
Snum NUMBER(4),
CONSTRAINT fk_salespeople FOREIGN KEY (Snum) REFERENCES
SalesPeople(Snum)
);
O/P:
Goo Averag Goo Averag Good Satisfactory Good Satisfactory Good Averag
d (2) e (1) d (2) e (1) (2) (1) (2) (1) (2) e (1)
Rubrics 1 2 3 4 5 Total
Marks
Experiment No: 3
FLOOR(), SIN()…
Date:
Explanation:
Observations:
O/P:
O/P:
O/P:
O/P:
O/P:
O/P:
O/P:
SELECT 24 % 2 AS ModulusResult;
O/P:
O/P:
SELECT
COS(2) AS CosineValue,
SIN(2) AS SineValue,
TAN(2) AS TangentValue;
O/P:
Database Management System (3130703)
SELECT
SIGN(-25) AS SignNegative25,
SIGN(25) AS SignPositive25,
SIGN(0) AS SignZero;
O/P:
Rubrics 1 2 3 4 5 Total
Marks
Experiment No: 4
Date:
Explanation:
(a) Write a SQL query to perform a cross product of the account and loan tables, retrieving
all possible combinations of records.
QUERY:-
SELECT *
FROM account
CROSS JOIN loan;
O/P:-
(b) Write a SQL query to retrieve the account holder's name and loan amount for accounts
that have taken a loan using an inner join.
QUERY:-
SELECT Account.name, Loan.loan_amt
FROM Account
INNER JOIN loan ON Account.name, Loan.loan_amt;
O/P:-
(c) Write a SQL query to retrieve all loans, and if an account exists for the loan, display the
account holder's name. For loans without an account, show NULL for the account name.
QUERY:-
SELECT Loan.loan_no, Loan.loan_amt, Account.Name
FROM Loan
LEFT JOIN Account ON Loan.acc_no = Account.acc_no;
O/P:-
Database Management System (3130703)
(d) Write a SQL query to display all data from the account and loan tables using a natural
join (assuming both tables have acc_no as a common column).
QUERY:-
SELECT *
FROM Account
NATURAL JOIN Loan;
O/P:-
(e) Write a SQL query to find all accounts with a balance greater than 50,000 and display
their loan details using a subquery with an inner join.
QUERY:-
SELECT Loan.loan_no, Loan.loan_amt, Loan.Interest_rate, Loan.Loan_date,
Loan.Remaining_loan
FROM Loan
INNER JOIN (SELECT acc_no FROM Account WHERE Balance > 50000) AS
HighBalanceAccounts
ON Loan.acc_no = HighBalanceAccounts.acc_no;
O/P:-
Goo Averag Goo Averag Good Satisfactory Good Satisfactory Good Averag
d (2) e (1) d (2) e (1) (2) (1) (2) (1) (2) e (1)
Rubrics 1 2 3 4 5 Total
Marks
Experiment No: 5
Date:
Explanation:
String Functions
(a)Find out length of string “hello world”.
(b)Change the case of ‘HELLO WORLD’ string to lower case.
(c)Change the case of ‘hello world’ to upper case.
(d)Display each word initial letter as capital letter: government polytechnic for girls.
(e)Find ‘put’ from string ‘computer’.
(f)Add 10 star on left side of India string.
(g)Add 10 star on right side of India string.
(h)Trim ‘ion’ from ‘information’.
(i)Trim ‘info’ from ‘information’.
Date Functions
(a)Add 3 months in current date.
(b)Display months between date: ’17-02-04’ and ’17-02-05’.
(c)Display last date of month ‘2-feb-06’.
(d)If the date is 31-jul-13 then find out the date of friendship day.
Observations:
O/P:
O/P:
Database Management System (3130703)
O/P:
-- (d) Display each word's initial letter as a capital letter: government polytechnic for girls.
QUERY:
SELECT INITCAP('government polytechnic for girls') AS CapitalizedWords;
O/P:
O/P:
O/P:
QUERY:
SELECT RPAD('India', LENGTH('India') + 10, '*') AS RightStarredString;
O/P:
O/P:
O/P:
Rubrics 1 2 3 4 5 Total
Marks
Database Management System (3130703)
Experiment No: 6
Date:
Explanation:
Study of JOIN to Retrieve Data from Multiple Tables
● Retrieve Account Holder Name and Loan Amount
Write a SQL query to display the account holder's name and loan amount for each
loan by joining the account and loan tables.
● Find Accounts with Loans Taken
Write a SQL query to list the account holder names and remaining loan amounts for
accounts that have taken a loan, using a JOIN.
● List Accounts without Loans
Write a SQL query to find all account holder names from the account table who
haven't taken a loan by using a LEFT JOIN.
UNION & MINUS Operations
● Use UNION to Combine Account and Loan Data
Write a SQL query to display the acc_no from both the account table and the loan
table using the UNION operator (without duplicates).
● Use MINUS to Find Accounts Without Loans
Write a SQL query to display the account numbers of all accounts in the account table
that are not present in the loan table using the MINUS operator.
Observations:
Retrieve Account Holder Name and Loan Amount
Write a SQL query to display the account holder's name and loan amount for each loan by
joining the account and loan tables.
Query:
SELECT Account.Name, Loan.loan_amt
FROM Account
INNER JOIN Loan ON Account.acc_no = Loan.acc_no;
O/P:
O/P:
O/P:
O/P:-
Database Management System (3130703)
O/P:-
Rubrics 1 2 3 4 5 Total
Marks
Experiment No: 7
Date:
Explanation:
Find Loan Accounts with Highest Loan Amount Write a SQL query to find the account(s)
with the highest loan amount using a subquery.
Find Accounts with Remaining Loan Greater than Average Write a SQL query to display
the loan accounts where the remaining loan is greater than the average remaining loan using a
subquery.
List Loan Accounts with Interest Rates Higher than 8% Write a SQL query to find all
loan accounts where the interest rate is higher than the average interest rate, using a subquery.
Observations:
Find Loan Accounts with Highest Loan Amount Write a SQL query to find the account(s)
with the highest loan amount using a subquery
Query:
SELECT *
FROM Loan
WHERE loan_amt = (SELECT MAX(loan_amt) FROM Loan);
O/P:-
Find Accounts with Remaining Loan Greater than Average Write a SQL query to display
the loan accounts where the remaining loan is greater than the average remaining loan using a
subquery.
Query:
SELECT *
FROM Loan
WHERE Remaining_loan > (SELECT AVG(Remaining_loan) FROM Loan);
O/P:-
List Loan Accounts with Interest Rates Higher than 8% Write a SQL query to find all
loan accounts where the interest rate is higher than the average interest rate, using a subquery.
Query:
SELECT *
Database Management System (3130703)
FROM Loan
WHERE Interest_rate > (SELECT AVG(Interest_rate) FROM Loan);
O/P:-
Rubrics 1 2 3 4 5 Total
Marks
Experiment No: 8
Date:
Explanation:
Database Management System (3130703)
SUM() Function
Write a SQL query to calculate the total balance of all accounts in the table.
MIN() Function
Write a SQL query to find the account with the minimum balance in the table.
MAX() Function
Write a SQL query to find the account with the maximum balance in the table.
AVG() Function
Write a SQL query to find the average balance of all accounts.
COUNT() Function
Write a SQL query to count how many accounts have taken a loan (loan_taken is 'YES').
Observations:
SUM() Function
Write a SQL query to calculate the total balance of all accounts in the table.
Query:
SELECT SUM(Balance) AS Total_Balance
FROM Account;
O/P:
MIN() Function
Write a SQL query to find the account with the minimum balance in the table.
Query:
SELECT *
FROM Account
WHERE Balance = (SELECT MIN(Balance) FROM Account);
O/P:
Database Management System (3130703)
MAX() Function
Write a SQL query to find the account with the maximum balance in the table.
Query:
SELECT *
FROM Account
WHERE Balance = (SELECT MAX(Balance) FROM Account);
O/P:
AVG() Function
Write a SQL query to find the average balance of all accounts.
Query:
SELECT AVG(Balance) AS Average_Balance
FROM Account;
O/P:
COUNT() Function
Write a SQL query to count how many accounts have taken a loan (loan_taken is 'YES').
Query:
SELECT COUNT(*) AS Accounts_With_Loan
FROM Account
WHERE loan_taken = 'Yes';
O/P:-
Database Management System (3130703)
Query:
SELECT City, SUM(Balance) AS Total_Balance
FROM Account
GROUP BY City;
O/P:
Query:
SELECT
MIN(Balance) AS Minimum_Balance,
MAX(Balance) AS Maximum_Balance,
AVG(Balance) AS Average_Balance
FROM Account;
O/P:-
Goo Averag Goo Averag Good Satisfactory Good Satisfactory Good Averag
d (2) e (1) d (2) e (1) (2) (1) (2) (1) (2) e (1)
Rubrics 1 2 3 4 5 Total
Marks
Experiment No: 9
Date:
Explanation:
Database Management System (3130703)
Observations:
O/P:
Database Management System (3130703)
O/P:
Query:
ROLLBACK;
Rubrics 1 2 3 4 5 Total
Marks
Experiment No: 10
Date:
2. Functions
Write a PL/SQL function that calculates and returns the total balance of all accounts in a
specific city. Then, use this function to get the total balance for the city 'Mehsana'.
3. Triggers
Create a trigger that automatically updates the Remaining_loan whenever the loan_amt is
updated in the Loan table.
4. Stored Procedures
Write a stored procedure that retrieves and displays the loan details (loan amount, interest
rate and remaining loan) for a specific account number.
5. Cursors
Write a PL/SQL block using a cursor to fetch and display all accounts along with their loan
amounts and remaining loan from the Loan and Account tables.
Observations:
Query:
-- Begin the transaction
SET AUTOCOMMIT OFF;
SAVEPOINT before_insert;
O/P:
2. Functions
Write a PL/SQL function that calculates and returns the total balance of all accounts in a
specific city. Then, use this function to get the total balance for the city 'Mehsana'.
Query:
Use db;
DELIMITER //
RETURNS DECIMAL(10, 2)
DETERMINISTIC
BEGIN
END //
DELIMITER ;
Using function:
O/P:
Rubrics 1 2 3 4 5 Total
Marks