Pages

Tuesday, October 18, 2011

My First T-SQL Stored Procedure

I have not got around with creating T-SQL stored procedures till today. Currently, I had developed a website utilizing the Entity Framework Methods. This is a very simplistic stored procedure as it is my first.

 

   1: -- ================================================
   2: -- Template generated from Template Explorer using:
   3: -- Create Procedure (New Menu).SQL
   4: --
   5: -- Use the Specify Values for Template Parameters 
   6: -- command (Ctrl-Shift-M) to fill in the parameter 
   7: -- values below.
   8: --
   9: -- This block of comments will not be included in
  10: -- the definition of the procedure.
  11: -- ================================================
  12: SET ANSI_NULLS ON
  13: GO
  14: SET QUOTED_IDENTIFIER ON
  15: GO
  16: -- =============================================
  17: -- Author:        Kirk deDoes
  18: -- Create date: October 18, 2011
  19: -- Description:    Inserts a new record into the TourLeg table.
  20: -- =============================================
  21: CREATE PROCEDURE [dbo].[InsertLeg]
  22:            @leg nchar(150),
  23:            @description text,
  24:            @sort int,
  25:            @state nchar(5)
  26: AS
  27: BEGIN
  28:     -- SET NOCOUNT ON added to prevent extra result sets from
  29:     -- interfering with SELECT statements.
  30: SET NOCOUNT ON;
  31: INSERT INTO [adminDB].[dbo].[TourLeg]
  32:            ([leg]
  33:            ,[description]
  34:            ,[sort]
  35:            ,[state])
  36:      VALUES
  37:            (
  38:            @leg,
  39:            @description,
  40:            @sort,
  41:            @state
  42:            )
  43: END
  44:  
  45: -- Returns Identity value of the newly inseerted record.
  46: SELECT SCOPE_IDENTITY() AS [ID];
  47:  
  48: GO
  49:  

Nice! Open-mouthed smile

No comments:

Post a Comment