Search icon
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Learn SQL using MySQL in One Day and Learn It Well

You're reading from  Learn SQL using MySQL in One Day and Learn It Well

Product type Book
Published in Apr 2024
Publisher Packt
ISBN-13 9781836205678
Pages 121 pages
Edition 1st Edition
Languages
Author (1):
Jamie Chan Jamie Chan
Profile icon Jamie Chan

Stored Routines

 

Next, let’s move on to stored routines.

 

A stored routine is a set of SQL statements that are grouped, named and stored together in the server. Do not worry if this does not make much sense to you at the moment. We’ll discuss it in greater depth later.

 

There are two types of stored routines - stored procedures and stored functions.

 

Stored Procedures

 

Let’s first look at stored procedures.

 

We can create a stored procedure using the syntax below:

 

DELIMITER $$

 

CREATE PROCEDURE name_of_procedure([parameters, if any])

BEGIN

-- SQL Statements

END $$

 

DELIMITER ;

 

Most of the syntax is pretty similar to the syntax for creating a trigger.

 

The main difference is, instead of using CREATE TRIGGER, we use CREATE PROCEDURE to create the stored procedure.

 

In addition, we have a pair of parentheses after the CREATE PROCEDURE keywords.

 

These parentheses...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at €14.99/month. Cancel anytime}