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 | 

테이블 정의

설명

CREATE TABLE 문을 사용하여 새로운 테이블을 생성한다.

구문

CREATE {TABLE | CLASS} <table_name>

                   [ <subclass_definition> ]

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

                   [ 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 ( 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 : 생성할 테이블 이름을 지정한다(최대 255바이트).
  • column_definition :
    • column_name : 생성할 컬럼의 이름을 지정한다.
    • column_type : 컬럼의 데이터 타입을 지정한다.
    • [SHARED value  | DEFAULT value ] : 컬럼의 초기값을 지정한다. (자세한 내용은 컬럼 정의 참조)
    • column_constraints : 컬럼의 제약 조건을 지정하며 제약 조건의 종류에는 NOT NULL, UNIQUE, PRIMARY KEY, FOREIGN KEY가 있다(자세한 내용은 제약 조건 정의 참조). 
예제

 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)
);