0% found this document useful (0 votes)
6 views

Stored Procedure

Stored procedures are SQL functions stored in a database that encapsulate logic for database modifications. They offer benefits such as modularity, improved performance, centralized logic, and security. The document includes examples of creating and using stored procedures, as well as parameter modes like IN, OUT, and INOUT.

Uploaded by

raagaqaran1988
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Stored Procedure

Stored procedures are SQL functions stored in a database that encapsulate logic for database modifications. They offer benefits such as modularity, improved performance, centralized logic, and security. The document includes examples of creating and using stored procedures, as well as parameter modes like IN, OUT, and INOUT.

Uploaded by

raagaqaran1988
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

SUBJECT : DBMS II

TOPIC : STORED PROCEDURES

Lecturer Name: YAHYE


ADAM
DEFINITION OF STORED PROCEDURE

• A stored procedure is a function written in SQL and


stored in the database.

• They are primarily used to store logic and protocols for


making changes to the database.

FULL JOIN
BENEFITS OF STORED PROCEDURES

1. Modularity and Reusability


2. Improved Performance
3. Centralized Logic
4. Security
5. Transaction Management
6. Ease of Maintenance
7. FULL JOIN
Reduced Network Traffic
8. Encapsulation of Complex Logic
9. Caching
EXAMPLE

DELIMITER // The DELIMITER statement says


CREATE PROCEDURE GetAllStudent() what marks the end of a statement.
BEGIN We can’t use the semicolon (“;”)
SELECT * FROM Student; because that can be used in the
END // procedure.
FULL
DELIMITER ;
JOIN
It tells the MySql command line
interface not to execute the lines
CALL GetAllStudent();
until the delimiter is used again.
PARAMETERS IN STORED PROCEDURES

Parameters for stored procedures can have one of three modes


dictating how it is used:

IN
• Default mode, the caller must set the variable and the procedure can't modify it
• The procedure works on a copy

OUT FULL JOIN


• The procedure can set this variable, but can not read it before being set within the
procedure

INOUT
• Combination of the two previous The caller passes the parameter in and the procedure
may modify it
EXAMPLE: INSERTION SP
DELIMITER //
CREATE PROCEDURE InsertStudent(
IN p_student_name VARCHAR(50),
IN p_contact int,
IN p_address VARCHAR(50)
)
BEGIN
INSERT INTO student (studentName, contact, address)
VALUES ( p_student_name, p_contact, p_address);
END //
DELIMITER ;
T-SQL (MICROSOFT SQL SERVER)

CREATE PROCEDURE GetAllStudents This stored procedure will retrieve all


columns and rows from the specified table
AS when executed.
BEGIN
SELECT * FROM Student
If you have specific conditions or criteria for
selecting data, you can modify the SELECT
END; statement accordingly within the stored
procedure.

EXEC GetAllStudents;
USING WHERE CLAUSE

DELIMITER // To use where clause inside our sql query,


we need to pass the procedure the
required parameter to select that specific
CREATE PROCEDURE FindProduct( data from the database table
IN p_productID int
)
BEGIN
select * from products where productID = p_productID;
END //
DELIMITER ;

call FindProduct(3);
THE END
THANKS!

You might also like