Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
34 views52 pages

Lab Manual DBMS

The document outlines the lab file for the Database Management Systems course at SRM Institute of Science and Technology, detailing the practical record of a student named Lakshya. It includes a bonafide certificate, a list of experiments, and guidelines for laboratory record preparation, along with specific SQL tasks and queries for various database operations. The document serves as a comprehensive guide for students to complete their lab work and submit for evaluation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views52 pages

Lab Manual DBMS

The document outlines the lab file for the Database Management Systems course at SRM Institute of Science and Technology, detailing the practical record of a student named Lakshya. It includes a bonafide certificate, a list of experiments, and guidelines for laboratory record preparation, along with specific SQL tasks and queries for various database operations. The document serves as a comprehensive guide for students to complete their lab work and submit for evaluation.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 52

LAB FILE

Database Management Systems


(Subject Code: 21CSC205P)
II Year B.Tech (CSE) IV Semester

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

FACULTY OF ENGINEERING & TECHNOLOGY, SRM INSTITUTE OF SCIENCE &

TECHNOLOGY, DELHI-NCR CAMPUS, MODINAGAR


SIKRI KALAN, DELHI MEERUT ROAD, DIST.–GHAZIABAD-201204

www.srmimt.net

Even Semester (Jan-2024)


SRM Institute of Science and Technology
NCR Campus, Modinagar

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Reg. No. R A 2 3 1 1 0 0 3 0 3 0 2 0 6

BONAFIDE CERTIFICATE

It is to be certified that the Bonafide practical record submitted by Lakshya of 4th Semester/ 2nd
Year for Bachelor of Technology degree in the Department of Computer Science and
Engineering, NCR Campus, SRM Institute of Science and Technology, has been done for the
course Database Management Systems(21CSC205P), during the academic year session JAN-
2025 – MAY 2025.

Head of the Department Lab In-charge

--------------------------------- ---------------------------
Dr. AVNEESH VASHISHTHA (HOD) Ms. (A.P.)

Department of CSE Department of CSE

Submitted for the University Examination held on .

Examiner 1 Examiner 2
LIST OF EXPERIMENTS

Expt. Title of experiment


No.
1. Creating tables and writing Queries in SQL.

2. To implement various DML Operations on table

3. To Implement the restrictions/constraints on the table


4. To Alter the structure of the table
5. To implement the concept of Joins
6. To implement the concept of grouping of Data
7. To implement the concept of Sub Queries
8. To implement the concept of Indexes and views.

9. To implement the basics of PL/SQL.

10. To implement the concept of Cursor and Trigger

Content Beyond Syllabus


1. Write a program to implement REPORTS.
2. Write a program to implement FORMS.
GUIDELINES FOR LABORTORY RECORD PREPARATION

While preparing the lab records, the student is required to adhere to the following guidelines:

Contents to be included in Lab Records:


1. Cover page
2. Index
3. Experiments
Aim
Source code Input-
Output
DBMS Lab (21CSC205P)

Student Name Lakshya

Registration No. RA2311003030206

Section- Batch CSE (core) - D


SRM Institute of Science & Technology, Delhi NCR Campus
Department of Computer Science & Engineering

INDEX
Exp.
Experiment Date of Date of Faculty
No.
Name Conduction Submission Signature
1 Creating tables and writing Queries in
SQL
2 To implement various DML Operations
on table.
To implement the
3 restrictions/constraints on the table
4 To Alter the structure of the table.

5 To implement the concept of Joins.

6 To implement the concept of grouping


of Data.
7 Elaborate PL/SQL procedure with
suitable example.
8 Elaborate PL/SQL function with suitable
example.
9 Elaborate PL/SQL cursor with suitable
example.
10 Elaborate PL/SQL trigger with suitable
example.
Experiment No. 1

Name: Lakshya
Reg-No.: RA2311003030206

Aim: Creating tables and writing Queries in SQL


Q1. Create the following tables:

i) client_master

columnname datatype size


client_no varchar2 6
name varchar2 20
address1 varchar2 30
address2 varchar2 30
city varchar2 15
state varchar2 15
pincode number 6
bal_due number 10,2
ii) Product_master

Q2- Insert the following data into their respective tables:

Clientno Name city pincode state bal.due


0001 Ivan Bombay 400054 Maharashtra 15000
0002 Vandana Madras 780001 Tamilnadu 0
0003 Pramada Bombay 400057 Maharashtra 5000
0004 Basu Bombay 400056 Maharashtra 0
0005 Ravi Delhi 100001 2000
0006 Rukmini Bombay 400050 Maharashtra 0
Data for Product Master:

Product No. Desciption Profit % Unit Qty Reorder Sell Cost


Percent measured on hand lvl price price

P00001 1.44floppies 5 piece 100 20 525 500


P03453 Monitors 6 piece 10 3 12000 11200
P06734 Mouse 5 piece 20 5 1050 500
P07865 1.22 floppies 5 piece 100 20 525 500
P07868 Keyboards 2 piece 10 3 3150 3050
P07885 CD Drive 2.5 piece 10 3 5250 5100
P07965 540 HDD 4 piece 10 3 8400 8000
P07975 1.44 Drive 5 piece 10 3 1050 1000
P08865 1.22 Drive 5 piece 2 3 1050 1000
Q3:- On the basis of above two tables answer the following Queries:
i) Find out the names of all the clients.

ii) Retrieve the list of names and cities of all the clients.

iii) List the various products available from the product_master table.
iv) List all the clients who are located in Bombay.

v) Display the information for client no 0001 and 0002.

vi) Find the products with description as ‘1.44 drive’ and ‘1.22 Drive’.

vii) Find all the products whose sell price is greater than 5000.

viii) Find the list of all clients who stay in city ‘Bombay’ or city ‘Delhi’ or ‘Madras’.
ix) Find the product whose selling price is greater than 2000 and less than or equal to 5000.

x) List the name, city and state of clients not in the state of ‘Maharashtra’.
Experiment No.: 2
Name: Lakshya
Registration No.: RA2311003030206
Aim: To implement various DML Operations on table.

1 Change the selling price of ‘1.44 floppy drive to Rs.1150.00

2 Delete the record with client 0001 from the client master table.
3 Change the city of client_no’0005’ to Bombay.

4 Change the bal_due of client_no ‘0001, to 1000.

5 Find the products whose selling price is more than 1500 and also find
the new selling price as original selling price *15.
6 Find out the clients who stay in a city whose second letter is a.

7 Find out the name of all clients having ‘a’ as the second letter in their names.

8 List the products in sorted order of their description.


9 Count the total number of orders

10 Calculate the average price of all the products.

11 Calculate the minimum price of products.


12 Determine the maximum and minimum prices. Rename the tittle as
‘max_price’ and min_price respectively.

13 Count the number of products having price greater than or equal to 1500.
Experiment No.: 3
Name: Lakshya
Registration No.: RA2311003030206

Aim: To implement the restrictions/constraints on the table.


Question.1 Create the following tables:
i. Sales_master
Columnname Datatype Size
Salesman_no varchar2 6
Sal_name varchar2 20
Address varchar2
City varchar2 20
State varchar2 20
Pincode Number 6
Sal_amt Number 8,2
Tgt_to_get Number 6,2
Ytd_sales Number 6,2
Remarks Varchar2 30
ii. Sales_order:

Columnname Datatype Size


S_order_no varchar2 6
S_order_date Date 6
Client_no Varchar2 25
Dely_add Varchar2 6
Salesman_no Varchar2 6
Dely_type Char 1
Billed_yn Char 1
Dely_date Date
Order_status Varchar2 10

iii. Sales_order_details:

Column Datatype Size


S_order_no Varchar2 6
Product_no Varchar2 6
Qty_order Number 8
Qty_disp Number 8
Product_rate Number 10,2
Insert the following data into their respective tables using
insert statement:
i. Data for sales_man master table
Salesman_no Salesman Address City Pincode State Salamt Tgt_ YtdSales Remark
name to_get
500001 Kiran A/14 worli Bombay 400002 Mah 3000 100 50 Good
500002 Manish 65,Nariman Bombay 400001 Mah 3000 200 100 Good
500003 Ravi P-7 Bandra Bombay 400032 Mah 3000 200 100 Good
500004 Ashish A/5 Juhu Bombay 400044 Mah 3500 200 150 Good

ii. Data for salesorder table:

S_orderno S_orderdate Client no Delytype Bill yn Salesman no Delaydate


Orderstatus
019001 12-jan-96 0001 F N 50001 20-jan-96 Ip
019002 25-jan-96 0002 P N 50002 27-jan-96 C
016865 18-feb-96 0003 F Y 500003 20-feb-96 F
019003 03-apr-96 0001 F Y 500001 07-apr-96 F
046866 20-may-96 0004 P N 500002 22-may-96 C
010008 24-may-96 0005 F N 500004 26-may-96 Ip
iii. Data for sales_order_details table:
S_order no Product no Qty ordered Qty disp Product_rate

019001 P00001 4 4 525


019001 P07965 2 1 8400
019001 P07885 2 1 5250
019002 P00001 10 0 525
046865 P07868 3 3 3150
046865 P07885 10 10 5250
019003 P00001 4 4 1050
019003 P03453 2 2 1050
046866 P06734 1 1 12000
046866 P07965 1 0 8400
010008 P07975 1 0 1050
010008 P00001 10 5 525
Experiment No.: 4
Name: Lakshya
Registration No.: RA2311003030206

Aim: To Alter the structure of the table.


Question 1. Create the following tables:
Table Name: Challan_Header

Column name datatype size Attributes


Challan_no varchar2 6 Primary key
s_order_no varchar2 6 Foreign key
references
s_order_no of sales_order table
challan_date date not null
billed_yn char 1 values (‘Y’,’N’). Default ‘N’

Table Name: Challan_Details

Column name datatype size Attributes


Challan_no varchar2 6 Primary key/Foreign key references
Product_no of
product_master Qty_disp number 4,2 not null
Q2. Insert the following values into the challan header and challan_details tables:

1. Data for challan_header table


Challan No S_order No Challan Date Billed
CH9001 019001 12-DEC-95 Y
CH865 046865 12-NOV-95 Y
CH3965 010008 12-OCT-95 Y

2. Data for challan_details table


Challan No Product No Qty Disp
CH9001 P00001 4
CH9001 P07965 1
CH9001 P07885 1
CH6865 P07868 3
CH6865 P03453 4
CH6865 P00001 10
CH3965 P00001 5
CH3965 P07975 2
Answer the following Queries

Q1. Make the primary key to client_no in client_master.


Q2. Add a new column phone_no in the client_master table.

Q3. Add the not null constraint in the product_master table with the
columns description, profit percent, sell price and cost price.

Q4. Change the size of client_no field in the client_master table.

Q5. Select product_no, description where profit percent is between 20 and 30 both
inclusive.
Experiment No.: 5

Name: Lakshya
Registration No.: RA2311003030206

Aim: To implement the concept of Joins.


A.Consider the following schema for a Library Database:
1. BOOK (Book_id, Title, Publisher_Name, Pub_Year)

2. BOOK_AUTHORS (Book_id, Author_Name)

3. PUBLISHER (Name, Address, Phone)


4. BOOK_COPIES (Book_id, Branch_id, No-of_Copies)

5. CARD(Card_No)

6. BOOK_LENDING (Book_id, Branch_id, Card_No, Date_Out, Due_Date)

7. LIBRARY_BRANCH (Branch_id, Branch_Name, Address)


Inserting values in the table:
1. Table data: Book
2. Table data: Book_author
3. Table data: Publisher
4. Table data: Book_copies
5. Table data: Card
6. Table data: Book_lending
7. Table data: Library_branch

Queries:
1. Retrieve details of all books in the library – id, title, name of publisher,
authors, number of copies in each branch, etc.
2. Get the particulars of borrowers who have borrowed more than 3 books,
but from Jan 2017 to Jun 2017.

3. Delete a book in BOOK table. Update the contents of other tables to


reflect this data manipulation operation.

4. Create a view of all books and its number of copies that are currently
available in the library.
EXPERIMENT NO.: 6
Name: Lakshya
Registration No.: RA2311003030206

Aim: To implement the concept of grouping of Data.

QUERIES –
1. Find out the product which has been sold to ‘Ivan Sayross’.

2. Find out the product and their quantities that will have do delivered.
3. Find the product_no and description of moving products.

4. Find out the names of clients who have purchased ‘CD DRIVE’.

5. List the product_no and s_order_no of customers haaving qty ordered


less than fromtheorder details table for the product “1.44 floppies”.
6. Find the products and their quantities for the orders placed by ‘Vandan
Saitwal’ and “Ivan Bayross”.

7. Find the products and their quantities for the orders placed by client_no
“C00001” and “C00002”.
8. Find the order No, Client No and salesman No. where a client has been
received by more than one salesman.

9. Display the s_order_date in the format “dd-mm-yy” e.g., “12- feb-96”.


10. Find the date, 15 days after date.
Experiment No.: 7
Name: Lakshya
Registration No.: RA2311003030206

Aim: Elaborate PL/SQL procedure with suitable example.

Create procedure example


In this example, we are going to insert record in user table. So, you need to
create user table first.

Table creation:
Create table user
(Id number (10) primary
key, Name varchar2 (100));
Now write the procedure code to insert record in user table.
Procedure Code:
Create or replace procedure Insertuser1 (Id IN NUMBER, Name IN
VARCHAR2) Is/As
Begin
Insert into user values (id,
name); End;
/

Output:
Procedure Created

PL/SQL program to call procedure


Let's see the code to call above created
procedure. EXECUTE Insertuser(101,’Rahul’);

N
Insertuser1 (102,'Jimmy');
dbms_output.put_line ('record inserted
successfully'); END;
/
Experiment No.: 8
Name: Lakshya
Registration No.: RA2311003030206

Aim: Elaborate PL/SQL function with suitable example.

PL/SQL Function Example


Create or replace function adder (n1 in number, n2 in number)
Return
number
Is
n3
number
(8);
Begin
n3:=n1+
n2;
Return
n3; End;
/

Now write another program to call the function.


DECLARE
n3
number(2);
BEGIN
n3:= adder (11, 22);
dbms_output.put_line ('Addition is: ' || n3);
END;
/

OUTPUT:
Experiment No.: 9
Name: Lakshya
Registration No.: RA2311003030206

Aim: Elaborate PL/SQL cursor with suitable example.

PL/SQL Implicit Cursor Example


Create customers table and have records:
ID NAME AGE ADDRESS SALARY
1 Ramesh 23 Allahabad 20000
2 Suresh 22 Kanpur 22000
3 Mahesh 24 Ghaziabad 24000
4 Chandan 25 Noida 26000
5 Alex 21 Paris 28000
6 Sunita 20 Delhi 30000

Create procedure:
DECLARE
Total_rows
number (2);
BEGIN
UPDATE customers
SET salary = salary + 5000;
IF sql%notfound THEN
dbms_output.put_line ('no customers updated');
ELSIF sql%found THEN
total_rows :=
sql%rowcount;
dbms_output.put_line (total_rows || ' customers updated
'); END IF;
END;
/
Output:
6 customers updated
PL/SQL procedure successfully completed.

Now, if you check the records in customer table, you will find that the rows
are updated.

Select * from customers;


Experiment No.: 10
Name: Lakshya
Registration No.: RA2311003030206

Aim: Elaborate PL/SQL trigger with suitable example.

PL/SQL Trigger Example


Let's take a simple example to demonstrate the trigger. In this example, we are
using the following CUSTOMERS table:
Create table and have records:

ID NAME AGE ADDRESS SALARY


1 Ramesh 23 Allahabad 20000
2 Suresh 22 Kanpur 22000
3 Mahesh 24 Ghaziabad 24000
4 Chandan 25 Noida 26000
5 Alex 21 Paris 28000
6 Sunita 20 Delhi 30000

Create trigger:
Following trigger will display the salary difference between the old values and
new values:
CREATE OR REPLACE TRIGGER
display_salary_changes BEFORE DELETE OR
INSERT OR UPDATE ON customers FOR EACH
ROW
WHEN
(NEW.ID > 0)
DECLARE
sal_diff
number;
BEGIN
sal_diff := :NEW.salary - :OLD.salary;
dbms_output.put_line('Old salary: ' ||
:OLD.salary); dbms_output.put_line('New salary: '
|| :NEW.salary); dbms_output.put_line('Salary
difference: ' || sal_diff); END;
/
Check the salary difference by procedure:
Use the following code to get the old salary, new salary and salary difference after
the trigger created.
DECLARE
Total_rows
number (2); BEGIN
UPDATE customers
SET salary = salary + 5000;
IF sql%notfound THEN
dbms_output.put_line ('no customers updated');
ELSIF sql%found
THEN total_rows:=
sql%rowcount;
dbms_output.put_line (total_rows || ' customers
updated '); END IF;
END;
/

You might also like