Sunday, June 5, 2011

What is Table Valued Parameter in SqlSever 2008?

Sample Code From Database Front


Create Tabel Structure in Database


Database view


--Traditional Approach for Creating Insert SP
-- =============================================
-- Author: Bimlesh Singh
-- Create date: 05th June 2011
-- Description: Stored Procedure without Table Valued Parameter
-- =============================================
CREATE PROCEDURE usp_Insert
-- Add the parameters for the stored procedure here
@ID int ,
@Name
nchar(10),
@Address_Line 1
nchar(10),
@Address_Line 2
nchar(10),
@Pin Code
int
AS
BEGIN
-- Insert statements for procedure here
INSERT INTO Student VALUES (@ID,@Name,@Address_Line 1,@Address_Line 2,@Pin Code)
END
GO


--As per below screenshot we can see multiple times we call the same SP for Insertion





--TVP(Table Valued Parameter) Approach for Creating SP
-- =============================================
-- Author: Bimlesh Singh
-- Create date: 05th June 2011
-- Description: Stored Procedure without Table Valued Parameter
-- =============================================
CREATE PROCEDURE usp_Modified_Insert
-- Add the parameters for the stored procedure here
@StudentType
Student Type
AS
BEGIN
-- Insert statements for procedure here
INSERT INTO Student SELECT * FROM @StudentType
END
GO


--From below screenshot we can see we need just the refernce of TVP for Insertion and i.e OneTime effort.













1 comment:

Bimlesh Singh said...
This comment has been removed by the author.