The new Table type allows you to save a table definition in the database which can be reused later to define table variables, stored procedure parameters and functions. To create a Type, we use the CREATE TYPE clause, for example:
CREATE TYPE dbo.ProductList as TABLE (
ProductName varchar(200) NULL,
ProductCategory varchar(200) NOT NULL)
Important Notes:
The metadata is visible using sys.table_types
Variables/parameters cannot be set to NULL – if no table is supplied, an empty table is generated
Not affected by transaction rollbacks
Do not cause recompilations
Examples
Create Table-Type Variables | DECLARE @t as dbo.ProductList; |
Creating a Stored Procedure with a Table-typed Parameter | CREATE PROC dbo.uspGetOrdersforProduct ( |
Passing Table-parameters into Stored Procedures | DECLARE @t as dbo.ProductList; EXEC dbo.uspGetOrdersforProduct @t |