Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page: CUBRID 8.3.0 |  CUBRID 8.3.1 |  CUBRID 8.4.0 |  CUBRID 8.4.1 |  CUBRID 8.4.3 |  CUBRID 9.0.0 | 

Table Definition

Description

To create a table, use the CREATE TABLE syntax.

Syntax

CREATE {TABLE | CLASS} <table_name>

                   [ <subclass_definition> ]

                   [ ( <column_definition> [,<table_constraint>]... ) ]

                   [ AUTO_INCREMENT = initial_value ] ]

                   [ CLASS ATTRIBUTE ( <column_definition_comma_list> ) ]

                   [ METHOD <method_definition_comma_list> ]

                   [ FILE <method_file_comma_list> ]

                   [ INHERIT <resolution_comma_list> ]

                   [ REUSE_OID ]

<column_definition> ::=

column_name column_type [[ <default_or_shared> ] | [ <column_constraint> ]]...

 

<default_or_shared> ::=

{SHARED <value_specification> | DEFAULT <value_specification> } |

AUTO_INCREMENT [(seed, increment)]

 

<column_constraint> ::=

NOT NULL | UNIQUE | PRIMARY KEY | FOREIGN KEY <referential definition>

 

<table_constraint> ::=

[ CONSTRAINT [ <constraint_name> ] ] UNIQUE [ KEY | INDEX ]( column_name_comma_list ) |

[ { KEY | INDEX } [ <constraint_name> ]( column_name_comma_list ) |

[ PRIMARY KEY ( column_name_comma_list )] |

[ <referential_constraint> ]

 

<referential_constraint> ::=

FOREIGN KEY [ <foreign_key_name> ]( column_name_comma_list ) <referential definition>

 

<referential definition> ::=

REFERENCES [ referenced_table_name ] ( column_name_comma_list )

[ <referential_triggered_action> ... ]

 

<referential_triggered_action> ::=

{ ON UPDATE <referential_action> } |

{ ON DELETE <referential_action> } |

{ ON CACHE OBJECT cache_object_column_name }

 

<referential_action> ::=

CASCADE | RESTRICT | NO ACTION | SET NULL

 

<subclass_definition> ::=

{ UNDER | AS SUBCLASS OF } table_name_comma_list

 

<method_definition> ::=

[ CLASS ] method_name

[ ( [ argument_type_comma_list ] ) ]

[ result_type ]

[ FUNCTION  function_name ]

 

<resolution> ::=

[ CLASS ] { column_name | method_name } OF superclass_name

[ AS alias ]

  • table_name : Specifies the name of the table to be created (maximum : 255 bytes).
  • column_name : Specifies the name of the column to be created.
  • column_type : Specifies the data type of the column.
  • [SHARED value   | DEFAULT value ] : Specifies the initial value of the column (see Column Definition for more information).
  • column_constraints : Specifies the constraint of the column. Available constraints are NOT NULL, UNIQUE, PRIMARY KEY and FOREIGN KEY (see Constraint Definition for more information).
Example

CREATE TABLE olympic (

    host_year              INT      NOT NULL PRIMARY KEY,

    host_nation          VARCHAR(40) NOT NULL,

    host_city              VARCHAR(20) NOT NULL,

    opening_date        DATE              NOT NULL,

    closing_date        DATE              NOT NULL,

    mascot                    VARCHAR(20) ,

    slogan                    VARCHAR(40) ,

    introduction        VARCHAR(1500)

)