CREATE TABLE - statement of language DB_MSSQL

Create new database table. The table structure itself consists of individual columns. Each column has its own name, data type and possible other attributes. Each table in the SQL Server must have its own primary key (PRIMARY KEY attribute). The data are processed by rows in the table.

CREATE TABLE table_name


  column_name data_type [ NULL | NOT NULL ] [ PRIMARY KEY | UNIQUE ] [ IDENTITY ] [ DEFAULT default_expression ] [ CHECK check_expression ]

  [, ...]


table_name Name of the table.
column_name Name of the column.
data_type column data type (bigint, int, smallint, tinyint, bit, decimal, numeric, money, smallmoney, float, real, datetime, smalldatetime, char, varchar, ntext, binary, varbinary, image).
NULL Enable using NULL value in the column.
NOT NULL Disable using NULL value in the column.
PRIMARY KEY Defines column as the primary key of the table (UNIQUE by default but UNIQUE mustn't be stated).
UNIQUE Values in this column must be unique (writing the record with the value that already exists in this column, fails).
IDENTITY Column (often primary key) whose unique value is supplied by the SQL Server itself on writing (only 1 such column is enabled in the table).
DEFAULT Definition of the default value, used on inserting new record, provided that the value for this column is not stated.
default_expression The result of this expression is used as the default value.
CHECK On inserting or editing the value its check will be performed. If the check fails, the whole operation fails.
check_expression The check itself where the expression result defines if the operation is valid or not.
Create new table data with columns time (time, primary key, mustn't be NULL), 'flags' (integer, mustn't be NULL, default value of 0) and 'value' (real number, mustn't be NULL, default value of 0).
  time datetime PRIMARY KEY NOT NULL,
  flags smallint NOT NULL DEFAULT 0,
  value float NOT NULL DEFAULT 0
© MICROSYS, spol. s r. o.Tavičská 845/21 703 00 Ostrava-Vítkovice