0% found this document useful (0 votes)
92 views41 pages

DBMS Manual4

This document is a laboratory manual for the Database Management System course (3130703) for B.E. Semester 3 students at Vishwakarma Government Engineering College. It outlines the course objectives, practical experiments, and expected competencies, emphasizing hands-on experience with SQL and PL/SQL. The manual aims to enhance students' skills in database design, implementation, and management, while providing guidelines for both faculty and students to ensure effective learning outcomes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
92 views41 pages

DBMS Manual4

This document is a laboratory manual for the Database Management System course (3130703) for B.E. Semester 3 students at Vishwakarma Government Engineering College. It outlines the course objectives, practical experiments, and expected competencies, emphasizing hands-on experience with SQL and PL/SQL. The manual aims to enhance students' skills in database design, implementation, and management, while providing guidelines for both faculty and students to ensure effective learning outcomes.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

A Laboratory Manual for

Database Management System


(3130703)

B.E. Semester 3
(Information & Communication Technology)

Directorate of Technical Education, Gandhinagar,


Gujarat
Vishwakarma Government Engineering College
Certificate
This is to certify that Prajapati Nayan Rameshbhai Enrollment No.
230170132052 of B.E. Semester 3 Information & Communication Technology
of this Institute (GTU Code:17 ) has satisfactorily completed the Practical /
Tutorial work for the subject Database Management System (3130703) for the
academic year 2024-25.

Place: __________
Date:

Name and Sign of Faculty member

Head of the Department


Preface

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

▪ To provide globally competitive technical education


▪ Remove geographical imbalances and inconsistencies
▪ Develop student friendly resources with a special focus on girls’ education and support to
▪ weaker sections
▪ Develop programs relevant to industry and create a vibrant pool of technical professionals

Institute’s Vision

▪ To create an ecosystem for proliferation of socially responsible and technically sound


engineers, innovators and entrepreneurs.

Institute’s Mission

▪ To develop state-of-the-art laboratories and well-equipped academic infrastructure.


▪ To motivate faculty and staff for qualification up-gradation, and enhancement of subject
knowledge.
▪ To promote research, innovation and real-life problem-solving skills.
▪ To strengthen linkages with industries, academic and research organizations.
▪ To reinforce concern for sustainability, natural resource conservation and social
responsibility.

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

▪ To establish cutting-edge laboratories and ensure a well-equipped academic infrastructure


that incorporates state-of-the-art technology.
▪ To inspire and encourage faculty and staff to pursue qualifications and upgrade their
expertise, thereby enhancing their subject knowledge.
▪ To foster a culture of research, promote consultancy work, and facilitate the development
of entrepreneurship skills.
▪ To strengthen industry connections to facilitate excellent job placements and provide
students with valuable real-world exposure.
▪ To actively encourage, engage, and support students in initiatives that promote
environmental and social well-being.
Database Management System (3130703)

Program Educational Objectives (PEOs)

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

Program Specific Outcomes (PSOs)

▪ Graduates will demonstrate a strong foundation in core concepts of Information and


Communication Technology (ICT) engineering, including knowledge of hardware and
software components, networking principles, and system design.
▪ Graduates will be capable of applying their knowledge of ICT engineering to develop
innovative solutions for real-world challenges in diverse application domains, such as
communication networks, cybersecurity, data management, and software development.
▪ Graduates will possess the ability to analyze, design, and develop ICT systems, applying
appropriate methodologies, algorithms, and tools to solve complex engineering problems.
Database Management System (3130703)

Practical – Course Outcome matrix

Course Outcomes (COs):


CO_3130703.1 Recognize the various elements of Database Management Systems
CO_3130703.2 Given a problem statement, identify the entities and their relations and draw an E-R
diagram and design database applying normalization.
CO_3130703.3 Solve the given problem using Relational Algebra, Relational Calculus, SQL and
PL/SQL
CO_3130703.4 Apply and relate the concepts of transaction, concurrency control, recovery and security
in database
CO_3130703.5 Recognize the purpose of query processing, optimization and demonstrate the SQL query
evaluation.
C C C C C
Sr.
Objective(s) of Experiment O O O O O
No.
1 2 3 4 5

To study DDL and DML Commands I & II in SQL.


● Create Insert Update Delete Drop TRUNCATE Table
1. queries. √ √
● Describe Table for displaying Meta Data
● Data Types Varchar2(n), Char(n), Number(n,m)……
● SELECT & FROM clause for searching from table.

To study Constraints and Pattern Matching SQL.


2. ● Specify NOT NULL Constraint √ √
● Specify Primary Key & UNIQUE Constraint
● Specify Foreign Key Constraint

To study In-built Functions and Grouping Statement in SQL.


3. ● Numeric Functions: ABS(), MOD(), POWER(), SQRT(), √
EXP(), CEIL(), FLOOR(), SIN()…

To study Joins and Sub-query in SQL.


4. ● Cross Product operation √
● Inner Join & Outer Join, Natural Join
● To fetch data from multiple tables.

To Study Single-row functions in SQL


● String Functions: INITCAP(), LOWER(), UPPER(),
5. CONCAT(), LPAD(), LTRIM(), SUBSTR(), LENGTH(), √
INSTR().
● Date Functions: ADD_MONTHS(), LAST_DAY(),
NEXT_DAY(), MONTH_BETWEEN()

6. To Study Data from Multiple tables I & II √


● Study of Join to retrieve data from multiple tables.
● UNION & MINUS Operations.

7. To study Concept of sub query in SQL. √


● Forming complex query using Sub Query

8. To study Manipulating Data with aggregate functions √


● SUM(), MIN(), MAX(), AVG(), COUNT() aggregate functions
for summarization & analysis of data.
9. √
Database Management System (3130703)

To study Security and Privileges commands in SQL.


● GRANT , REVOKE , COMMIT, ROLLBACK,
commands.

10. To Study Transaction control commands & PL/SQL. √


● Functions, Triggers, Stored Procedures, Cursors.
Database Management System (3130703)

Industry Relevant Skills

The following industry relevant competency is expected to be developed in the student by


undertaking the practical work of this laboratory.
1. Will be able to design and develop a database for any application
2. Access and modify the created database as per requirement
3. Optimize data access also understand the internal function of various component of
DBMS

Guidelines for Faculty members

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.

Instructions for Students

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.

Common Safety Instructions

Students are expected to


1) switch on the PC carefully (not to use wet hands)
2) shutdown the PC properly at the end of your Lab
3) carefully Handle the peripherals (Mouse, Keyboard, Network cable etc)
4) Use Laptop in lab after getting permission from Teacher
Database Management System (3130703)

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

To study DDL and DML Commands I & II in SQL.


● Create Insert Update Delete Drop TRUNCATE
Table queries.
1. ● Describe Table for displaying Meta Data
● Data Types Varchar2(n), Char(n), Number(n,m)
……
● SELECT & FROM clause for searching from
table.

To study Constraints and Pattern Matching SQL.


2. ● Specify NOT NULL Constraint
● Specify Primary Key & UNIQUE Constraint
● Specify Foreign Key Constraint

To study In-built Functions and Grouping Statement in SQL.


3. ● Numeric Functions: ABS(), MOD(), POWER(),
SQRT(), EXP(), CEIL(), FLOOR(), SIN()…

To study Joins and Sub-query in SQL.


4. ● Cross Product operation
● Inner Join & Outer Join, Natural Join
● To fetch data from multiple tables.

To Study Single-row functions in SQL


● String Functions: INITCAP(), LOWER(),
5. UPPER(), CONCAT(), LPAD(), LTRIM(),
SUBSTR(), LENGTH(), INSTR().
● Date Functions: ADD_MONTHS(), LAST_DAY(),
NEXT_DAY(), MONTH_BETWEEN()

6. To Study Data from Multiple tables I & II


● Study of Join to retrieve data from multiple tables.
● UNION & MINUS Operations.

7. To study Concept of sub query in SQL.


● Forming complex query using Sub Query

To study Manipulating Data with aggregate functions


8. ● SUM(), MIN(), MAX(), AVG(), COUNT()
aggregate functions
for summarization & analysis of data.

9. To study Security and Privileges commands in SQL.


● GRANT , REVOKE , COMMIT, ROLLBACK,
commands.

10.
To Study Transaction control commands & PL/SQL.
Database Management System (3130703)

● Functions, Triggers, Stored Procedures, Cursors.


Total
Database Management System (3130703)

Experiment No: 1

To study DDL and DML Commands I & II in SQL.


● Create Insert Update Delete Drop TRUNCATE Table queries.
● Describe Table for displaying Meta Data
● Data Types Varchar2(n), Char(n), Number(n,m)……
● SELECT & FROM clause for searching from table.

Date:

Explanation:

Design the below given schemas using SQL Command -”Create”.


Use Data Types Varchar2(n), Char(n), Number(n,m)……

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

Insert data in above tables using SQL Command “Insert”.

(A) Account
acc_no Name City Balance loan_taken

A001 Patel Jigar Mehsana 50000 Yes

A002 Patel Ramesh Mehsana 50000 Yes

A003 Dave Hardik Ahmedabad 75000 No

A004 Soni Hetal Ahmedabad 100000 No

A005 Soni Atul Vadodara 100000 Yes

(B) Loan
loan_no acc_no loan_amt Interest_ Loan_date Remaining
rate _loan
L001 A001 100000 7 1-jan-20 75000

L002 A002 300000 9 18-may-20 150000

L003 A005 500000 11 15-june-20 300000


Database Management System (3130703)

Retrieve data from above tables using Data SQL command- “Select”

(a)Display selected rows and selected columns of table Account.


(b)Display selected rows and all columns of table loan.
(c)Display the branch wise balance from account table.

Write SQL queries to use Update, delete, drop and truncate.

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

(b)Delete the records whose account no is A004

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

(b)For each loan holders Increase the interest rate 2%

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)

Rubric wise marks obtained:


Knowledge of Programming Team work (2) Communication Ethics(2)
subject (2) Skill Skill (2)
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
Database Management System (3130703)

Experiment No: 2

To study Constraints and Pattern Matching SQL.


● Specify NOT NULL Constraint
● Specify Primary Key & UNIQUE Constraint
● Specify Foreign Key Constraint

Date:

Explanation:

Apply the concept of integrity/data constraints while creating/altering a table:

(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)

Sname VARCHAR2(20) NOT NULL,


City VARCHAR2(15),
Mobile_No NUMBER(10)
);

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:

Rubric wise marks obtained:


Knowledge of Programming Team work (2) Communication Ethics(2)
subject (2) Skill Skill (2)
Database Management System (3130703)

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

To study In-built Functions and Grouping Statement in SQL.


● Numeric Functions: ABS(), MOD(), POWER(), SQRT(), EXP(), CEIL(),
Database Management System (3130703)

FLOOR(), SIN()…

Date:

Explanation:

Write SQL queries to use various numeric functions


(a) Display integer value of 125.25.
(b) Display absolute value of (-15)
(c) Display ceil value of 55.65
(d) Display floor value of 100.2
(e) Display the square root of 16.
(f) Display square root of 20.
(g) Display result of 12 raised to 6.
(h) Display result of 24 mod 2.
(i) Show value of e3.
(j) 2 is angle in radius find out cos, sin, tan value of 2.
(k) Show output of sign(-25), sign(25), sign(0).

Observations:

(a) Display integer value of 125.25


QUERY:

SELECT CAST(125.25 AS INT) AS IntegerValue;

O/P:

(b) Display absolute value of (-15)


QUERY:

SELECT ABS(-15) AS AbsoluteValue;

O/P:

(c) Display ceil value of 55.65


QUERY:
Database Management System (3130703)

SELECT CEILING(55.65) AS CeilValue;

O/P:

(d) Display floor value of 100.2


QUERT:

SELECT FLOOR(100.2) AS FloorValue;

O/P:

(e) Display the square root of 16


QUERY:

SELECT SQRT(16) AS SquareRoot16;

O/P:

(f) Display square root of 20


QUERY:

SELECT SQRT(20) AS SquareRoot20;

O/P:

(g) Display result of 12 raised to 6


QUERY:
SELECT POWER(12, 6) AS TwelveRaisedToSix;
Database Management System (3130703)

O/P:

(h) Display result of 24 mod 2


QUERY:

SELECT 24 % 2 AS ModulusResult;

O/P:

(i) Show value of e^3


QUERY:

SELECT EXP(3) AS ExponentialValue;

O/P:

(j) 2 is angle in radians; find cos, sin, tan value of 2


QUERY:

SELECT
COS(2) AS CosineValue,
SIN(2) AS SineValue,
TAN(2) AS TangentValue;

O/P:
Database Management System (3130703)

(k) Show output of sign(-25), sign(25), sign(0)


QUERY:

SELECT
SIGN(-25) AS SignNegative25,
SIGN(25) AS SignPositive25,
SIGN(0) AS SignZero;

O/P:

Rubric wise marks obtained:


Knowledge of Programming Team work (2) Communication Ethics(2)
subject (2) Skill Skill (2)
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: 4

To study Joins and Sub-query in SQL.


● Cross Product operation
● Inner Join & Outer Join, Natural Join
To fetch data from multiple tables.
Database Management System (3130703)

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

Rubric wise marks obtained:


Knowledge of Programming Team work (2) Communication Ethics(2)
subject (2) Skill Skill (2)
Database Management System (3130703)

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

To Study Single-row functions in SQL


Database Management System (3130703)

● String Functions: INITCAP(), LOWER(), UPPER(), CONCAT(), LPAD(),


LTRIM(), SUBSTR(), LENGTH(), INSTR().
● Date Functions: ADD_MONTHS(), LAST_DAY(), NEXT_DAY(),
MONTH_BETWEEN()

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:

-- (a) Find out length of string “hello world”.


QUERY:
SELECT LENGTH('hello world') AS StringLength;

O/P:

-- (b) Change the case of ‘HELLO WORLD’ string to lower case.


QUERY:
SELECT LOWER('HELLO WORLD') AS LowerCaseString;

O/P:
Database Management System (3130703)

-- (c) Change the case of ‘hello world’ to upper case.


QUERY:
SELECT UPPER('hello world') AS UpperCaseString;

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:

-- (e) Find ‘put’ from string ‘computer’.


QUERY:
SELECT POSITION('put' IN 'computer') AS PositionOfSubstring;

O/P:

-- (f) Add 10 stars on the left side of 'India' string.


QUERY:
SELECT LPAD('India', LENGTH('India') + 10, '*') AS LeftStarredString;

O/P:

-- (g) Add 10 stars on the right side of 'India' string.


Database Management System (3130703)

QUERY:
SELECT RPAD('India', LENGTH('India') + 10, '*') AS RightStarredString;

O/P:

-- (h) Trim ‘ion’ from ‘information’.


QUERY:
SELECT REPLACE('information', 'ion', '') AS TrimmedString1;

O/P:

-- (i) Trim ‘info’ from ‘information’.


QUERY:
SELECT REPLACE('information', 'info', '') AS TrimmedString2;

O/P:

Rubric wise marks obtained:


Knowledge of Programming Team work (2) Communication Ethics(2)
subject (2) Skill Skill (2)
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
Database Management System (3130703)

Experiment No: 6

To Study Data from Multiple tables I & II


● Study of Join to retrieve data from multiple tables.
● UNION & MINUS Operations.

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:

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.
Query:
SELECT Account.Name, Loan.Remaining_loan
FROM Account
Database Management System (3130703)

INNER JOIN Loan ON Account.acc_no = Loan.acc_no;

O/P:

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.
Query:
SELECT Account.Name
FROM Account
LEFT JOIN Loan ON Account.acc_no = Loan.acc_no
WHERE Loan.acc_no IS NULL;

O/P:

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).
Query:
SELECT acc_no FROM Account
UNION
SELECT acc_no FROM Loan;

O/P:-
Database Management System (3130703)

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.
Query:
SELECT acc_no FROM Account
MINUS
SELECT acc_no FROM Loan;

O/P:-

Rubric wise marks obtained:


Knowledge of Programming Team work (2) Communication Ethics(2)
subject (2) Skill Skill (2)
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: 7

To study Concept of sub query in SQL.


● Forming complex query using Sub Query

Date:

Explanation:

Table: LOAN (use table loan from experiment-1)


Database Management System (3130703)

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

Rubric wise marks obtained:


Knowledge of Programming Team work (2) Communication Ethics(2)
subject (2) Skill Skill (2)
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: 8

To study Manipulating Data with aggregate functions


● SUM(), MIN(), MAX(), AVG(), COUNT() aggregate functions for
summarization & analysis of data.

Date:

Explanation:
Database Management System (3130703)

Table: ACCOUNT (use table account of experiment 1)

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

Group with SUM() Function


Write a SQL query to calculate the total balance of accounts in each city.

Combining Aggregate Functions


Write a SQL query to display the minimum, maximum, and average balance of accounts in
the table.

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)

Group with SUM() Function


Write a SQL query to calculate the total balance of accounts in each city.

Query:
SELECT City, SUM(Balance) AS Total_Balance
FROM Account
GROUP BY City;

O/P:

Combining Aggregate Functions


Write a SQL query to display the minimum, maximum, and average balance of accounts in
the table.

Query:
SELECT
MIN(Balance) AS Minimum_Balance,
MAX(Balance) AS Maximum_Balance,
AVG(Balance) AS Average_Balance
FROM Account;

O/P:-

Rubric wise marks obtained:


Knowledge of Programming Team work (2) Communication Ethics(2)
subject (2) Skill Skill (2)
Database Management System (3130703)

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

To study Security and Privileges commands in SQL.


● GRANT, REVOKE, COMMIT, ROLLBACK commands.

Date:

Explanation:
Database Management System (3130703)

(a)Create a new user User1.


(b)Grant connect, resource and dba rights to user1.
(c)Grant all permissions of account table to user1.
(d)Remove select permission on account table for user1.
(e) Insert a new record into the account table.
(f)Commit the transaction.
(g)Delete Record from the account table
(h)Rollback the transaction.

Observations:

(a)Create a new user User1.


Query:
CREATE LOGIN User1 WITH PASSWORD = 'your_password';
CREATE USER User1 FOR LOGIN User1;

(b)Grant connect, resource and dba rights to user1.


Query:
EXEC sp_addrolemember 'db_datareader', 'User1';
EXEC sp_addrolemember 'db_datawriter', 'User1';
EXEC sp_addrolemember 'db_owner', 'User1';

(c)Grant all permissions of account table to user1.


Query:
GRANT SELECT, INSERT, UPDATE, DELETE ON account TO User1;

(d)Remove select permission on account table for user1.


Query:
REVOKE SELECT ON account TO User1;

(e) Insert a new record into the account table.


Query:
INSERT INTO account (acc_no, Name, City, Balance, loan_taken)
VALUES ('A006', 'Patel Vikram', 'Surat', 60000, 'No');
SELECT * FROM Account;
GO

O/P:
Database Management System (3130703)

(f)Commit the transaction.


Query:
COMMIT;

(g)Delete Record from the account table


Query:
DELETE FROM account
WHERE acc_no = 'A006';
SELECT * FROM Account;
GO

O/P:

(h)Rollback the transaction.

Query:
ROLLBACK;

Rubric wise marks obtained:


Knowledge of Programming Team work (2) Communication Ethics(2)
subject (2) Skill Skill (2)
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: 10

To Study Transaction control commands & PL/SQL.


● Functions, Triggers, Stored Procedures, Cursors.

Date:

Explanation: (use table account & loan from experiment-1)


Database Management System (3130703)

1. Transaction Control Commands


Write a transaction where:
● You update the balance of account A001.
● Insert a new loan record in the Loan table.
● Use SAVEPOINT before the insert.
● Roll back the insertion but commit the balance update.

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:

1. Transaction Control Commands


Write a transaction where:
● You update the balance of account A001.
● Insert a new loan record in the Loan table.
● Use SAVEPOINT before the insert.
● Roll back the insertion but commit the balance update.

Query:
-- Begin the transaction
SET AUTOCOMMIT OFF;

-- Step 1: Update the balance of account A001


UPDATE Account
SET Balance = Balance + 10000 -- Example increment
WHERE acc_no = 'A001';

-- Step 2: Set a savepoint before the insert


Database Management System (3130703)

SAVEPOINT before_insert;

-- Step 3: Insert a new loan record in the Loan table


INSERT INTO Loan (loan_no, acc_no, loan_amt, Interest_rate, Loan_date, Remaining_loan)
VALUES ('L004', 'A001', 50000, 8, TO_DATE('2023-10-02', 'YYYY-MM-DD'), 50000);

-- Step 4: Rollback the insertion


ROLLBACK TO before_insert;

-- Step 5: Commit the balance update


COMMIT;

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

CREATE FUNCTION get_total_balance_by_city(city_name VARCHAR(50))

RETURNS DECIMAL(10, 2)

DETERMINISTIC

BEGIN

DECLARE total_balance DECIMAL(10, 2) DEFAULT 0;


-- Calculate total balance for the given city
SELECT IFNULL(SUM(Balance), 0) INTO total_balance
FROM Account

WHERE City = city_name;


-- Return the total balance
RETURN total_balance;
Database Management System (3130703)

END //

DELIMITER ;

Using function:

SELECT get_total_balance_by_city('Ahmedabad') AS total_balance;

O/P:

Rubric wise marks obtained:


Knowledge of Programming Team work (2) Communication Ethics(2)
subject (2) Skill Skill (2)
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

You might also like