SlideShare a Scribd company logo
Stored procedure
Disclaimer: This presentation is prepared by trainees of
baabtra as a part of mentoring program. This is not official
document of baabtra –Mentoring Partner
Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt .
Ltd
STORED POCEDURE
ASNA.C.A
kunjulaloos@gmail.com
www.facebook.com/userna
me
twitter.com/username
in.linkedin.com/in/profilena
me
9048331776
• A stored procedure is a subroutine available to
application that access a relational database
system. A stored procedure is actually stored in
the database data dictionary.
• Stored procedures are more than just tools for
performing repetitive tasks. There are two main
types of stored procedure – system stored
procedures and user-defined stored procedures.
In sql server it is very easy to create stored
procedure. We can create a stored procedure in
sql server management studio (SSMS) in
following way:
• Creating stored procure using server
management studio (SSMS
Step 1: Expand your database name node in
SSMS. Then expand Programmability node as
shown in the following screenshot:
Step 2: Right click on Stored Procedures node
and click on New stored procedure...
•
Step 3: It will generate following sql script in new query page:--
================================================
-- Template generated from Template Explorer using:
-- Create Procedure (New Menu).SQL
--
-- Use the Specify Values for Template Parameters
-- command (Ctrl-Shift-M) to fill in the parameter
-- values below.
--
-- This block of comments will not be included in
-- the definition of the procedure.
-- ================================================
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: <Author,,Name>
-- Create date: <Create Date,,>
-- Description: <Description,,>
-- =============================================
CREATE PROCEDURE <Procedure_Name, sysname, ProcedureName>
-- Add the parameters for the stored procedure here
<@Param1, sysname, @p1> <Datatype_For_Param1, , int> =<Default_Value_For_Para
m1, , 0>,
<@Param2, sysname, @p2> <Datatype_For_Param2, , int> =<Default_Value_For_Para
m2, , 0>
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT <@Param1, sysname, @p1>, <@Param2, sysname, @p2>
END
GO
Step 4: Now edit above script like stored procedure name,
parameters, procedure body etc according to your requirement
. For example:
-- =============================================
-- Author: Exact Help
-- Create date: 02/10/2012
-- Description: My first stored procedure
-- =============================================
CREATE PROCEDURE My_First_Proc
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT 'Exact Help'
END
GO
Step 5: To create My_First_Proc stored procedure press F5 button
of your keyboard or click on Execute button in SSMS.
• Step 6: After creating it will be stored
inside Programmability node. To re-open or
edit it expand programmability node and right
click on your stored procedure name and
choose modify option.
You will get the script of your stored procedure. In this case it will be script of My_First_Proc. Which will
something like this:
USE [Exact]
GO
/****** Object: StoredProcedure [dbo].[My_First_Proc] Script Date: 02/10/2012 10:02:40 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Exact Help
-- Create date: 02/10/2012
-- Description: My first stored procedure
-- =============================================
ALTER PROCEDURE [dbo].[My_First_Proc]
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT 'Exact Help'
END
Stored procedure
Example
CREATE PROCEDURE sp_GetInventory
@location varchar(10)
AS
SELECT Product, Quantity
FROM Inventory
WHERE Warehouse = @location
EXECUTE sp_GetInventory 'FL’
Advantages of stored procedure
• Precompiled execution
SQL Server compiles each stored procedure once and
then reutilizes the execution plan. This results in
tremendous performance boosts when stored
procedures are called repeatedly.
• Reduced client/server traffic
If network bandwidth is a concern in your environment,
you'll be happy to learn that stored procedures can
reduce long SQLqueries to a single line that is
transmitted over the wire.
• Efficient reuse of code and programming abstraction
Stored procedures can be used by multiple users and client
programs. If you utilize them in a planned manner, you'll find
the development cycle takes less time.
• Enhanced security controls
You can grant users permission to execute a stored procedure
independently of underlying table permissions.
If this presentation helped you, please visit our
page facebook.com/baabtra and like it.
Thanks in advance.
www.baabtra.com | www.massbaab.com |www.baabte.com
Contact Us
Emarald Mall (Big Bazar Building)
Mavoor Road, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
NC Complex, Near Bus Stand
Mukkam, Kozhikode,
Kerala, India.
Ph: + 91 – 495 40 25 550
Start up Village
Eranakulam,
Kerala, India.
Email: info@baabtra.com

More Related Content

PPTX
Advance Sql Server Store procedure Presentation
PPTX
Sql storeprocedure
PPTX
Store procedures
DOCX
Memory Management
ODP
MySQL Scaling Presentation
PDF
Stored-Procedures-Presentation
PDF
Performance Schema for MySQL troubleshooting
PPTX
Stored procedure
Advance Sql Server Store procedure Presentation
Sql storeprocedure
Store procedures
Memory Management
MySQL Scaling Presentation
Stored-Procedures-Presentation
Performance Schema for MySQL troubleshooting
Stored procedure

What's hot (13)

PPTX
Caching and invalidating with managed store
 
PPTX
Caching and invalidating with managed store
PDF
AutoDOPandRest
PDF
MySQL Troubleshooting with the Performance Schema
PDF
PostgreSQL Portland Performance Practice Project - Database Test 2 Howto
DOC
Quick guide to PostgreSQL Performance Tuning
PDF
Scaling symfony apps
PDF
Full Stack Toronto - the 3R Stack
ODP
Caching and tuning fun for high scalability @ FOSDEM 2012
ODP
phptek13 - Caching and tuning fun tutorial
PDF
UKOUG 2011: Practical MySQL Tuning
PPTX
Proof of Concept with Real Application Testing 12c
DOCX
Physical_Standby_Database_R12.2.4
Caching and invalidating with managed store
 
Caching and invalidating with managed store
AutoDOPandRest
MySQL Troubleshooting with the Performance Schema
PostgreSQL Portland Performance Practice Project - Database Test 2 Howto
Quick guide to PostgreSQL Performance Tuning
Scaling symfony apps
Full Stack Toronto - the 3R Stack
Caching and tuning fun for high scalability @ FOSDEM 2012
phptek13 - Caching and tuning fun tutorial
UKOUG 2011: Practical MySQL Tuning
Proof of Concept with Real Application Testing 12c
Physical_Standby_Database_R12.2.4
Ad

Viewers also liked (9)

Ad

Similar to Stored procedure (20)

PPTX
STORED-PROCEDURE.pptxjsjjdjdjcjcjdkksksksk
PDF
Sherlock holmes for dba’s
PDF
Instrumenting plugins for Performance Schema
PPTX
Mule with stored procedure
PPT
lecture13.ppt
PDF
Sap basis
PPTX
LVOUG meetup #4 - Case Study 10g to 11g
PPTX
QSpiders - Installation and Brief Dose of Load Runner
PPTX
Stored procedures by thanveer danish melayi
ODP
Caching and tuning fun for high scalability
PPT
NoCOUG Presentation on Oracle RAT
PDF
Aspects of 10 Tuning
PDF
22-4_PerformanceTuningUsingtheAdvisorFramework.pdf
PDF
BeeGFS Training.pdf
PPT
Architecting cloud
ODP
Common schema my sql uc 2012
ODP
Common schema my sql uc 2012
PDF
Profiling PHP with Xdebug / Webgrind
PDF
MySQL & Expression Engine EEUK2013
ODP
Pyramid deployment
STORED-PROCEDURE.pptxjsjjdjdjcjcjdkksksksk
Sherlock holmes for dba’s
Instrumenting plugins for Performance Schema
Mule with stored procedure
lecture13.ppt
Sap basis
LVOUG meetup #4 - Case Study 10g to 11g
QSpiders - Installation and Brief Dose of Load Runner
Stored procedures by thanveer danish melayi
Caching and tuning fun for high scalability
NoCOUG Presentation on Oracle RAT
Aspects of 10 Tuning
22-4_PerformanceTuningUsingtheAdvisorFramework.pdf
BeeGFS Training.pdf
Architecting cloud
Common schema my sql uc 2012
Common schema my sql uc 2012
Profiling PHP with Xdebug / Webgrind
MySQL & Expression Engine EEUK2013
Pyramid deployment

More from baabtra.com - No. 1 supplier of quality freshers (20)

PPTX
Agile methodology and scrum development
PDF
Baabtra.com programming at school
PDF
99LMS for Enterprises - LMS that you will love
PPTX
Chapter 6 database normalisation
PPTX
Chapter 5 transactions and dcl statements
PPTX
Chapter 4 functions, views, indexing
PPTX
PPTX
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
PPTX
Chapter 1 introduction to sql server
PPTX
Chapter 1 introduction to sql server
Agile methodology and scrum development
Baabtra.com programming at school
99LMS for Enterprises - LMS that you will love
Chapter 6 database normalisation
Chapter 5 transactions and dcl statements
Chapter 4 functions, views, indexing
Chapter 2 grouping,scalar and aggergate functions,joins inner join,outer join
Chapter 1 introduction to sql server
Chapter 1 introduction to sql server

Recently uploaded (20)

PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Cloud computing and distributed systems.
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Machine learning based COVID-19 study performance prediction
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Modernizing your data center with Dell and AMD
DOCX
The AUB Centre for AI in Media Proposal.docx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PPTX
Big Data Technologies - Introduction.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PPTX
MYSQL Presentation for SQL database connectivity
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
Unlocking AI with Model Context Protocol (MCP)
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
Encapsulation_ Review paper, used for researhc scholars
Chapter 3 Spatial Domain Image Processing.pdf
Cloud computing and distributed systems.
NewMind AI Weekly Chronicles - August'25 Week I
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Machine learning based COVID-19 study performance prediction
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Modernizing your data center with Dell and AMD
The AUB Centre for AI in Media Proposal.docx
Reach Out and Touch Someone: Haptics and Empathic Computing
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Understanding_Digital_Forensics_Presentation.pptx
Big Data Technologies - Introduction.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
MYSQL Presentation for SQL database connectivity
20250228 LYD VKU AI Blended-Learning.pptx

Stored procedure

  • 2. Disclaimer: This presentation is prepared by trainees of baabtra as a part of mentoring program. This is not official document of baabtra –Mentoring Partner Baabtra-Mentoring Partner is the mentoring division of baabte System Technologies Pvt . Ltd
  • 4. • A stored procedure is a subroutine available to application that access a relational database system. A stored procedure is actually stored in the database data dictionary. • Stored procedures are more than just tools for performing repetitive tasks. There are two main types of stored procedure – system stored procedures and user-defined stored procedures. In sql server it is very easy to create stored procedure. We can create a stored procedure in sql server management studio (SSMS) in following way:
  • 5. • Creating stored procure using server management studio (SSMS Step 1: Expand your database name node in SSMS. Then expand Programmability node as shown in the following screenshot:
  • 6. Step 2: Right click on Stored Procedures node and click on New stored procedure...
  • 7. • Step 3: It will generate following sql script in new query page:-- ================================================ -- Template generated from Template Explorer using: -- Create Procedure (New Menu).SQL -- -- Use the Specify Values for Template Parameters -- command (Ctrl-Shift-M) to fill in the parameter -- values below. -- -- This block of comments will not be included in -- the definition of the procedure. -- ================================================ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: <Author,,Name> -- Create date: <Create Date,,> -- Description: <Description,,> -- =============================================
  • 8. CREATE PROCEDURE <Procedure_Name, sysname, ProcedureName> -- Add the parameters for the stored procedure here <@Param1, sysname, @p1> <Datatype_For_Param1, , int> =<Default_Value_For_Para m1, , 0>, <@Param2, sysname, @p2> <Datatype_For_Param2, , int> =<Default_Value_For_Para m2, , 0> AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; -- Insert statements for procedure here SELECT <@Param1, sysname, @p1>, <@Param2, sysname, @p2> END GO
  • 9. Step 4: Now edit above script like stored procedure name, parameters, procedure body etc according to your requirement . For example: -- ============================================= -- Author: Exact Help -- Create date: 02/10/2012 -- Description: My first stored procedure -- ============================================= CREATE PROCEDURE My_First_Proc AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; SELECT 'Exact Help' END GO Step 5: To create My_First_Proc stored procedure press F5 button of your keyboard or click on Execute button in SSMS.
  • 10. • Step 6: After creating it will be stored inside Programmability node. To re-open or edit it expand programmability node and right click on your stored procedure name and choose modify option.
  • 11. You will get the script of your stored procedure. In this case it will be script of My_First_Proc. Which will something like this: USE [Exact] GO /****** Object: StoredProcedure [dbo].[My_First_Proc] Script Date: 02/10/2012 10:02:40 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO -- ============================================= -- Author: Exact Help -- Create date: 02/10/2012 -- Description: My first stored procedure -- ============================================= ALTER PROCEDURE [dbo].[My_First_Proc] AS BEGIN -- SET NOCOUNT ON added to prevent extra result sets from -- interfering with SELECT statements. SET NOCOUNT ON; SELECT 'Exact Help' END
  • 13. Example CREATE PROCEDURE sp_GetInventory @location varchar(10) AS SELECT Product, Quantity FROM Inventory WHERE Warehouse = @location EXECUTE sp_GetInventory 'FL’
  • 14. Advantages of stored procedure • Precompiled execution SQL Server compiles each stored procedure once and then reutilizes the execution plan. This results in tremendous performance boosts when stored procedures are called repeatedly. • Reduced client/server traffic If network bandwidth is a concern in your environment, you'll be happy to learn that stored procedures can reduce long SQLqueries to a single line that is transmitted over the wire.
  • 15. • Efficient reuse of code and programming abstraction Stored procedures can be used by multiple users and client programs. If you utilize them in a planned manner, you'll find the development cycle takes less time. • Enhanced security controls You can grant users permission to execute a stored procedure independently of underlying table permissions.
  • 16. If this presentation helped you, please visit our page facebook.com/baabtra and like it. Thanks in advance. www.baabtra.com | www.massbaab.com |www.baabte.com
  • 17. Contact Us Emarald Mall (Big Bazar Building) Mavoor Road, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 NC Complex, Near Bus Stand Mukkam, Kozhikode, Kerala, India. Ph: + 91 – 495 40 25 550 Start up Village Eranakulam, Kerala, India. Email: info@baabtra.com