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

0% found this document useful (0 votes)
5 views5 pages

DBMS - Lab 13

This document outlines Lab 13 for the CS220 Database Systems course, focusing on stored procedures in SQL. It provides definitions, syntax, and examples of creating and executing stored procedures, along with specific tasks for students to complete. The objectives include understanding stored procedures and creating, altering, reading, and deleting them in a database context.

Uploaded by

murtaza rasheed
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)
5 views5 pages

DBMS - Lab 13

This document outlines Lab 13 for the CS220 Database Systems course, focusing on stored procedures in SQL. It provides definitions, syntax, and examples of creating and executing stored procedures, along with specific tasks for students to complete. The objectives include understanding stored procedures and creating, altering, reading, and deleting them in a database context.

Uploaded by

murtaza rasheed
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
You are on page 1/ 5

Faculty of Computing

CS220: Database Systems


Class: BSCS-14
Lab 13: Stored Procedures
Date: May 8, 2025
Time: 2:00-5:00
Instructor: Dr Shams Qazi

Lab Engineer: Sundas Dawood

SUBMITTED BY:
MUHAMMAD MURTAZA
503477
CS-14A

Lab 13: Stored procedures


Introduction
What is a Stored Procedure?
A stored procedure is a prepared SQL code that you can save, so the code can be reused over and
over again.
So if you have an SQL query that you write over and over again, save it as a stored procedure,
and then just call it to execute it.
You can also pass parameters to a stored procedure, so that the stored procedure can act based on
the parameter value(s) that is passed.
Stored Procedure Syntax
DELIMITER //
CREATE PROCEDURE procedure_name ( IN | OUT | INOUT parameter_name
parameter_datatype (length), … )
BEGIN
SQL statements
END //
DELIMITER ;
Execute a Stored Procedure
call procedure_name;

Create given table: (Below is a selection from the "Customers" table in the Northwind sample
database)
CustomerI CustomerName ContactNa Address City PostalCode Country
D me

1 Alfreds Maria Obere Str. 57 Berlin 12209 Germany


Futterkiste Anders

2 Ana Trujillo Ana Trujillo Avda. de la México 05021 Mexico


Emparedados y Constitución D.F.
helados 2222

3 Antonio Moreno Antonio Mataderos México 05023 Mexico


Taquería Moreno 2312 D.F.

4 Around the Thomas 120 Hanover London WA1 1DP UK


Horn Hardy Sq.

5 Berglunds Christina Berguvsvägen Luleå S-958 22 Sweden


snabbköp Berglund 8

Stored Procedure Example


The following SQL statement creates a stored procedure named "SelectAllCustomers" that
selects all records from the "Customers" table:
Example
CREATE PROCEDURE SelectAllCustomers ()
begin
SELECT * FROM Customers
end
Execute the stored procedure above as follows:
Example
call SelectAllCustomers;
Stored Procedure With One Parameter
The following SQL statement creates a stored procedure that selects Customers from a particular
City from the "Customers" table:
Example
CREATE PROCEDURE SelectAllCustomers (City nvarchar(30))
begin
SELECT * FROM Customers WHERE City = City
end
Execute the stored procedure above as follows:
Example
call SelectAllCustomers @City = 'London';
Stored Procedure With Multiple Parameters
Setting up multiple parameters is very easy. Just list each parameter and the data type separated
by a comma as shown below.
The following SQL statement creates a stored procedure that selects Customers from a particular
City with a particular PostalCode from the "Customers" table:
Example
CREATE PROCEDURE SelectAllCustomers (IN City nvarchar(30), IN
PostalCode nvarchar(10))
begin
SELECT * FROM Customers WHERE City = City AND PostalCode =
PostalCode
end
Execute the stored procedure above as follows:
Example
call SelectAllCustomers (City = 'London', PostalCode = 'WA1 1DP');

Objectives
Objective of this lab is to understand the concept pf Stored procedure.
Helping material:
https://phoenixnap.com/kb/mysql-stored-procedure

Task:
A. Create a Stored Procedure to Add a New Book to the Library
1. Create a table for books
2. Create a stored procedure to add a new book
3. Call the stored procedure to add a new book
B. Create, alter, read and delete Stored procedure of a table from your project
Deliverables:
Complete your lab tasks in SQL workbench and submit a word file with queries and the
screenshots of the results to all the questions attempted. Upload it on LMS. Late submissions
will not be accepted.

You might also like