Oracle SQL - CREATE TABLE Command


The SQL command to create tables is CREATE TABLE.

To create a table, you must specify a name for the new table, followed by a specification of all table columns.

The columns must be specified as a comma-separated list between parentheses.

You might also create a new table by inheriting properties from an existing one by running a CREATE TABLE ... AS SELECT statement

Column specifications normally consist of several components.

Each column specification starts with a column name, followed by the data type.

CREATE TABLE command supports two component types: column specifications and constraint specifications.

You can create new tables based on a subquery with the AS clause.

The CREATE TABLE ... AS SELECT ... command (known as CTAS) is comparable to one of the possibilities of the INSERT command.

With CTAS you create and populate the table in a single SQL command.

In this case, you can omit the column specifications between the parentheses. In CTAS commands, the new table always inherits the data types from the results of the subquery.

You can specify constraints in two ways:

  • As independent (out-of-line) components of the CREATE TABLE command
  • As inline constraints inside a column specification

You can use the DEFAULT option to specify a value to be used for INSERT commands.

Related Topics