Jump to content

Create (SQL)

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by AntiVandalBot (talk | contribs) at 16:24, 1 December 2006 (BOT - rv 87.248.178.161 (talk) to last version by 206.248.159.61). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

A CREATE statement in SQL creates an object inside of a relational database management system (RDBMS). The types of objects that can be created depends on which RDBMS is being used, but most support the creation TABLEs, INDEXes, USERs, and DATABASEs. Some systems (such as PostgreSQL) allow CREATE and other DDL commands to occur inside of a transaction and thus be rolled back.

CREATE TABLE

Perhaps the most common CREATE command is the CREATE TABLE command. The typical usage is:

CREATE [TEMP[ORARY]] TABLE [table name] ( [column definitions] ) [table parameters].

Column Definitions: A comma-separated list consisting of any of the following

  • Column definition: [column name] [data type] {NULL | NOT NULL} {column options}
  • Primary key definition: PRIMARY KEY ( [comma separated column list] )
  • CONSTRAINTS: {CONSTRAINT} [constraint definition]
  • RDBMS specific functionality

For example, the command to create a table named employees with a few sample columns would be:

CREATE TABLE employees (   
   id            INTEGER   PRIMARY KEY,
   first_name    CHAR(50)  null,
   last_name     CHAR(75)  not null,
   date_of_birth DATE      null
);

See also