云数据库 GAUSSDB-CREATE TABLE:语法格式

时间:2024-11-12 09:17:45

语法格式

  • 创建表。
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    CREATE [ [ GLOBAL | LOCAL ] { TEMPORARY | TEMP } | UN LOG GED ] TABLE [ IF NOT EXISTS ] table_name 
        ({ column_name data_type  [ CHARACTER SET | CHARSET charset ]
    [ compress_mode ] [ COLLATE collation ] [ column_constraint [ ... ] ]
            | table_constraint
            | LIKE source_table [ like_option [...] ] }
            [, ... ])
        [ WITH ( {storage_parameter = value} [, ... ] ) ]
        [ ON COMMIT { PRESERVE ROWS | DELETE ROWS } ]
        [ COMPRESS | NOCOMPRESS ]
        [ TABLESPACE tablespace_name ]
        [ DISTRIBUTE BY { REPLICATION | HASH ( column_name [, ...] ) 
        | RANGE ( column_name [, ...] ) { SLICE REFEREN CES  tablename | ( slice_less_than_item [, ...] )
        | ( slice_start_end_item [, ...] ) }
        | LIST ( column_name [, ...] ) { SLICE REFERENCES tablename | ( slice_values_item [, ...] ) }
        } ]
        [ TO { GROUP groupname | NODE ( nodename [, ... ] ) } ];
    
    • 其中列约束column_constraint为:
       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      [ CONSTRAINT constraint_name ]
      { NOT NULL |
        NULL |
        CHECK ( expression ) | 
        DEFAULT default_expr |
        GENERATED ALWAYS AS ( generation_expr ) [STORED] |
        AUTO_INCREMENT |
        UNIQUE [KEY] [ index_parameters ] |
        PRIMARY KEY [ index_parameters ] |
        ENCRYPTED WITH ( COLUMN_ENCRYPTION_KEY = column_encryption_key, ENCRYPTION_TYPE = encryption_type_value ) }
        REFERENCES reftable [ ( refcolumn ) ] [ MATCH FULL | MATCH PARTIAL | MATCH SIMPLE ]
          [ ON DELETE action ] [ ON UPDATE action ] }
      [ DEFERRABLE | NOT DEFERRABLE | INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
      
    • 其中表约束table_constraint为:
      1
      2
      3
      4
      5
      6
      [ CONSTRAINT constraint_name ]
      { CHECK ( expression ) |
        UNIQUE ( column_name [, ... ] ) [ index_parameters ] |
        PRIMARY KEY ( column_name [, ... ] ) [ index_parameters ] 
         }
      [ DEFERRABLE | NOT DEFERRABLE | INITIALLY DEFERRED | INITIALLY IMMEDIATE ]
      
    • 其中like选项like_option为:
      1
      { INCLUDING | EXCLUDING } { DEFAULTS | GENERATED | CONSTRAINTS | INDEXES | STORAGE | COMMENTS | PARTITION | RELOPTIONS | DISTRIBUTION | ALL }
      
    • 其中RANGE分布规则
      slice_less_than_item为:
      SLICE slice_name VALUES LESS THAN ({ expression | MAXVALUE } [, ...]) [ DATANODE datanode_name | ( datanode_name_list )]
      slice_start_end_item为:
      SLICE name {
      { START ( expression ) END ( expression ) EVERY ( expression ) } |
      { START ( literal ) END ( { literal | MAXVALUE } ) } |
      { START ( literal ) } |
      { END ( { literal | MAXVALUE } ) }
      }
    • 其中LIST分布规则slice_values_item为:
      SLICE name VALUES (expression [, ... ]) [DATANODE datanode_name | ( datanode_name_list )] |
      SLICE name VALUES (DEFAULT) [DATANODE datanode_name | ( datanode_name_list )]
其中索引参数index_parameters为:
1
2
[ WITH ( {storage_parameter = value} [, ... ] ) ]
[ USING INDEX TABLESPACE tablespace_name ]
support.huaweicloud.com/distributed-devg-v3-gaussdb/gaussdb-12-0540.html