Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Â
Stored procedure
1.
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
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