table (data type)
table variables, table-valued function results
What changes
- Input
- none
- Output or change
- none
Syntax at a glance
table_type_definition ::= TABLE ( { <column_definition> | <table_constraint> } [ , ...n ] )
Work example
Pass a small, typed rowset to a procedure or hold intermediate rows within a batch.
Declare keys and null rules explicitly, then compare a table variable with a temporary table for the expected row count.
Check your work A table variable has table-like scope and statistics behavior that differs from a temporary table.
Practice SQL
Open in SQL FlowDECLARE @items table (code varchar(8) NOT NULL PRIMARY KEY, quantity int NOT NULL); INSERT @items VALUES ('A1', 2); SELECT code, quantity FROM @items;
Open Microsoft Learn for full syntax, permissions, and details for your version.