该语句用来在数据库中创建一张新表。
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] table_name
(table_definition_list) [table_option_list] [partition_option] [AS] select;
CREATE [TEMPORARY] TABLE [IF NOT EXISTS] table_name
LIKE table_name;
table_definition_list:
table_definition [, table_definition ...]
table_definition:
column_definition
| [CONSTRAINT [constraint_name]] PRIMARY KEY index_desc
| [CONSTRAINT [constraint_name]] UNIQUE {INDEX | KEY} [index_name] index_desc
| {INDEX | KEY} [index_name] index_desc
| FULLTEXT [INDEX | KEY] [index_name] fulltext_index_desc
column_definition_list:
column_definition [, column_definition ...]
column_definition:
column_name data_type
[DEFAULT const_value] [AUTO_INCREMENT]
[NULL | NOT NULL] [[PRIMARY] KEY] [UNIQUE [KEY]] comment
index_desc:
(column_desc_list) [index_type] [index_option_list]
fulltext_index_desc:
(column_desc_list) CTXCAT(column_desc_list) [index_option_list]
column_desc_list:
column_desc [, column_desc ...]
column_desc:
column_name [(length)] [ASC | DESC]
index_type:
USING BTREE
index_option_list:
index_option [ index_option ...]
index_option:
[GLOBAL | LOCAL]
| block_size
| compression
| STORING(column_name_list)
| comment
table_option_list:
table_option [ table_option ...]
table_option:
[DEFAULT] {CHARSET | CHARACTER SET} [=] charset_name
| [DEFAULT] COLLATE [=] collation_name
| primary_zone
| replica_num
| table_tablegroup
| block_size
| compression
| AUTO_INCREMENT [=] INT_VALUE
| comment
| DUPLICATE_SCOPE [=] "none|zone|region|cluster"
| LOCALITY [=] "locality description"
| ROW_FORMAT [=] REDUNDANT|COMPACT|DYNAMIC|COMPRESSED|DEFAULT
| PCTFREE [=] num
partition_option:
PARTITION BY HASH(expression)
[subpartition_option] PARTITIONS partition_count
| PARTITION BY KEY([column_name_list])
[subpartition_option] PARTITIONS partition_count
| PARTITION BY RANGE {(expression) | COLUMNS (column_name_list)}
[subpartition_option] (range_partition_list)
| PARTITION BY LIST {(expression) | COLUMNS (column_name_list)}
[subpartition_option] PARTITIONS partition_count
subpartition_option:
SUBPARTITION BY HASH(expression)
SUBPARTITIONS subpartition_count
| SUBPARTITION BY KEY(column_name_list)
SUBPARTITIONS subpartition_count
| SUBPARTITION BY RANGE {(expression) | COLUMNS (column_name_list)}
(range_subpartition_list)
| SUBPARTITION BY LIST(expression)
range_partition_list:
range_partition [, range_partition ...]
range_partition:
PARTITION partition_name
VALUES LESS THAN {(expression_list) | MAXVALUE}
range_subpartition_list:
range_subpartition [, range_subpartition ...]
range_subpartition:
SUBPARTITION subpartition_name
VALUES LESS THAN {(expression_list) | MAXVALUE}
expression_list:
expression [, expression ...]
column_name_list:
column_name [, column_name ...]
partition_name_list:
partition_name [, partition_name ...]
partition_count | subpartition_count:
INT_VALUE
参数 | 描述 |
---|---|
DUPLICATE_SCOPE | 用来指定复制表属性,取值如下:
不指定 DUPLICATE_SCOPE 的情况下,默认值为 none。 |
ROW_FORMAT | 指定表是否开启 encoding 存储格式
|
BLOCK_SIZE | 指定表的微块大小 |
COMPRESSION | 指定表的压缩算法,取值如下:
|
CHARSET | CHARACTER SET | 指定表中列的默认字符集,可使用:utf8, utf8mb4, gbk, utf16, gb18030 |
COLLATE | 指定表中列的默认比较规则,可使用: utf8_bin, utf8_general_ci, utf8_unicode_ci, gbk_bin, gbk_chinese_ci, utf8mb4_general_ci, utf8mb4__general_cs, utf8mb4_bin, utf8mb4_unicode_ci, utf16_general_ci, utf16_bin, utf16_unicode_ci, gb18030_chinese_ci, gb18030_bin |
primary_zone | 指定主 Zone(副本 Leader 所在 Zone)。 |
replica_num | 指定副本数。 |
table_tablegroup | 指定表所属的 talegroup。 |
AUTO_INCREMENT | 指定表中自增列的初始值。 |
comment | 注释。 |
LOCALITY | 描述副本在 Zone 间的分布情况,如:F@z1,F@z2,F@z3,R@z4 表示 z1, z2, z3 为全功能副本,z4 为只读副本。 |
PCTFREE | 指定宏块保留空间百分比。 |
CREATE TABLE test (c1 int primary key, c2 VARCHAR(50)) REPLICA_NUM = 3, PRIMARY_ZONE = 'zone1';
CREATE TABLE item(id int, name varchar(10)) DUPLICATE_SCOPE="cluster";
CREATE TABLE t1 (c1 int primary key, c2 int, c3 int, index i1 (c2));
CREATE TABLE t1 (c1 int primary key, c2 int) partition by hash(c1) partitions 8;
CREATE TABLE t1 (c1 int, c2 int, c3 int)
partition by range(c1) subpartition by key(c2, c3) subpartitions 5
(partition p0 values less than(0), partition p1 values less than(100));
CREATE TABLE t1 (c1 varchar(10),
c2 varchar(10) charset gbk collate gbk_bin)
default charset utf8 collate utf8mb4_general_ci;
CREATE TABLE t1 (c1 int, c2 int, c3 varchar(64))
compression 'zstd_1.0'
ROW_FORMAT dynamic
pctfree 5;
备案信息: 粤ICP备15087711号-2
Copyright © 2008-2024 啊嘎哇在线工具箱 All Rights.
本站所有资料来源于网络,版权归原作者所有,仅作学习交流使用,如不慎侵犯了您的权利,请联系我们。