CREATE TABLE
defines columns, types, constraints, defaults, identity, computed columns, period, system-versioning, ledger
What changes
- Input
- column definitions; optional AS FileTable, graph, memory-optimized, temporal, ledger options
- Output or change
- new table (empty) in the catalog; #name creates a temp table
Syntax at a glance
CREATE TABLE { database_name.schema_name.table_name | schema_name.table_name | table_name } ( { <column_definition> } [ ,... n ] ) [ ; ]
Work example
A lab needs a small table with explicit types and a primary key.
Create the temporary table, inspect its key and null rules, then remove it in the same session.
Check your work The table accepts one valid row and rejects a duplicate key.
Practice SQL
Open in SQL FlowCREATE TABLE #PracticeItem (ItemId int NOT NULL PRIMARY KEY, Label nvarchar(40) NOT NULL);
INSERT INTO #PracticeItem (ItemId, Label) VALUES (1, N'Notebook');
SELECT ItemId, Label FROM #PracticeItem;
DROP TABLE #PracticeItem;
Open Microsoft Learn for full syntax, permissions, and details for your version.