CREATE TABLE#
Creates a new table in the virtual database.
Syntax#
A column definition gives a column name and data type, optionally followed by NULL /
NOT NULL, a DEFAULT, a collation or a column constraint. A table constraint defines a
PRIMARY KEY, FOREIGN KEY or CHECK constraint over one or more columns.
Querona also supports CREATE TABLE … AS SELECT (CTAS) to create and populate a table from a query in a single statement.
Arguments#
- table
The name of the new table.
- column definition
column_name data_type [ NULL | NOT NULL ] [ DEFAULT expression ] [ column_constraint ].- table constraint
A
PRIMARY KEY,FOREIGN KEYorCHECKconstraint.
Examples#
Create a table with a primary key:
CREATE TABLE dbo.Product (
Id int NOT NULL PRIMARY KEY,
Name nvarchar(100) NOT NULL,
Price decimal(10,2) NULL
);
Create and populate a table from a query (CTAS):
CREATE TABLE dbo.ActiveProduct AS
SELECT Id, Name, Price
FROM dbo.Product
WHERE Discontinued = 0;
See also