Table Valued Parameters
Using a table valued parameter to insert multiple rows to a table
Section titled “Using a table valued parameter to insert multiple rows to a table”First, define a used defined table type to use:
CREATE TYPE names as TABLE( FirstName varchar(10), LastName varchar(10))GOCreate the stored procedure:
CREATE PROCEDURE prInsertNames( @Names dbo.Names READONLY -- Note: You must specify the READONLY)AS
INSERT INTO dbo.TblNames (FirstName, LastName)SELECT FirstName, LastNameFROM @NamesGOExecuting the stored procedure:
DECLARE @names dbo.NamesINSERT INTO @Names VALUES('Zohar', 'Peled'),('First', 'Last')
EXEC dbo.prInsertNames @NamesRemarks
Section titled “Remarks”Table valued parameters (TVP for short) are parameters passed to a stored procedure or function that contains data that is table structured. Using table valued parameters requires creating a user defined table type for the parameter being used.
Tabled valued parameters are readonly parameters.