Stored procedure
Upcoming SlideShare
Loading in...5
×
 

Stored procedure

Stored procedure

Statistics

Views

Total Views
472
Views on SlideShare
472
Embed Views
0

Actions

Likes
0
Downloads
11
Comments
0

0 Embeds 0

No embeds

Accessibility

Categories

Upload Details

Uploaded via as Microsoft PowerPoint

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Stored procedure Stored procedure Presentation Transcript

    • 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
    • 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