Table Valued Parameters (TVPs) were introduced in SQL Server 2008. TVPs allow passing multiple rows of data to the server. It can be passed to a Stored Procedure as a parameter. It improves the performance of the application since it prevents several round trips to the server for saving the records in the database. Prior to TVPs we need to pass the data by delimiting with some characters and for doing that we need to write some logic for SQL Server for separating the data.
- TVPs are stored in Tempdb and can be created and destroyed automatically behind the scenes.
- We can have select or join against TVP.
- It is similar to temp tables, table variables or CTEs.
- It can be passed from client to server over a network.
Creating TVP in SQL Server
We will first create a table and then create a type of that. I have created a table named Students as in the following:
- CREATE TABLE [dbo].[Students](
- [StudentId] [int] NOT NULL,
- [FirstName] [varchar](50) NOT NULL,
- [LastName] [varchar](50) NOT NULL,
- [Email] [varchar](80) NOT NULL,
- [DateCreated] [datetime] NOT NULL,
- CONSTRAINT [PK_Students] PRIMARY KEY CLUSTERED
- (
- [StudentId] ASC
- )
- )
- GO
Now we will create a TVP for the preceding table.
- Create Type StudentsUDT as Table
- (
- StudentID int,
- FirstName varchar(50),
- LastName varchar(50),
- Email varchar(80)
- )
I have not created a DateCreated column in the TVP since I want this column value to be the latest depending on my SQL Server date. Now I will create a Stored Procedure that will accept this table value parameter as parameter and save multiple rows into the database.
Create proc usp_SaveStudents

vaibhav guptaPosted Oct 1, 2020, 7:37 PM
Thanks buddy again for helping , Its Vaibhav from India :)
David ConditPosted Jan 25, 2018, 5:49 PM
Thanks, Ritesh! This worked great for me.
PRAMOD DAS M.D. 1125936Posted May 13, 2015, 4:45 AM
I tried to add the procedure and bumped into the same message from VS2012. Ritesh, could u please tell which is the version of EF you are using. Thanks!
Priya DharshiniPosted Apr 23, 2015, 9:14 AM
Hey this worked in visual studio 2013 very well. But can this design work in VS2012 as well???
Gowtham RajamanickamPosted Apr 1, 2015, 1:07 AM
good show
srinivas RapakaPosted Nov 12, 2014, 5:03 AM
simply super . nice one
Guest UserPosted Aug 1, 2014, 10:46 PM
+1
Ravi ShekharPosted Jul 27, 2014, 7:18 AM
good one