Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 38 additions & 10 deletions sql-statements/sql-statement-create-index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,62 @@ This statement adds a new index to an existing table. It is an alternative synta

![CreateIndexStmt](/media/sqlgram/CreateIndexStmt.png)

**CreateIndexStmtUnique:**
**IndexKeyTypeOpt:**

![CreateIndexStmtUnique](/media/sqlgram/CreateIndexStmtUnique.png)
![IndexKeyTypeOpt](/media/sqlgram/IndexKeyTypeOpt.png)

**Identifier:**
**IfNotExists:**

![Identifier](/media/sqlgram/Identifier.png)
![IfNotExists](/media/sqlgram/IfNotExists.png)

**IndexTypeOpt:**

![IndexTypeOpt](/media/sqlgram/IndexTypeOpt.png)

**TableName:**
**IndexPartSpecificationList:**

![TableName](/media/sqlgram/TableName.png)

**IndexColNameList:**

![IndexColNameList](/media/sqlgram/IndexColNameList.png)
![IndexPartSpecificationList](/media/sqlgram/IndexPartSpecificationList.png)

**IndexOptionList:**

![IndexOptionList](/media/sqlgram/IndexOptionList.png)

**IndexLockAndAlgorithmOpt:**

![IndexLockAndAlgorithmOpt](/media/sqlgram/IndexLockAndAlgorithmOpt.png)

**IndexType:**

![IndexType](/media/sqlgram/IndexType.png)

**IndexPartSpecification:**

![IndexPartSpecification](/media/sqlgram/IndexPartSpecification.png)

**IndexOption:**

![IndexOption](/media/sqlgram/IndexOption.png)

**IndexTypeName:**

![IndexTypeName](/media/sqlgram/IndexTypeName.png)

**ColumnName:**

![ColumnName](/media/sqlgram/ColumnName.png)

**OptFieldLen:**

![OptFieldLen](/media/sqlgram/OptFieldLen.png)

**IndexNameList:**

![IndexNameList](/media/sqlgram/IndexNameList.png)

**KeyOrIndex:**

![KeyOrIndex](/media/sqlgram/KeyOrIndex.png)

## Examples

```sql
Expand Down
12 changes: 4 additions & 8 deletions sql-statements/sql-statement-create-sequence.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,6 @@ The `CREATE SEQUENCE` statement creates sequence objects in TiDB. The sequence i

![CreateSequenceStmt](/media/sqlgram/CreateSequenceStmt.png)

**OptTemporary:**

![OptTemporary](/media/sqlgram/OptTemporary.png)

**IfNotExists:**

![IfNotExists](/media/sqlgram/IfNotExists.png)
Expand All @@ -31,13 +27,13 @@ The `CREATE SEQUENCE` statement creates sequence objects in TiDB. The sequence i

![CreateSequenceOptionListOpt](/media/sqlgram/CreateSequenceOptionListOpt.png)

**SequenceOption:**
**SequenceOptionList:**

![SequenceOption](/media/sqlgram/SequenceOption.png)
![SequenceOptionList](/media/sqlgram/SequenceOptionList.png)

**CreateTableOptionListOpt:**
**SequenceOption:**

![CreateTableOptionListOpt](/media/sqlgram/CreateTableOptionListOpt.png)
![SequenceOption](/media/sqlgram/SequenceOption.png)

## Syntax

Expand Down
10 changes: 5 additions & 5 deletions sql-statements/sql-statement-create-table-like.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,12 @@ This statement copies the definition of an existing table, without copying any d

**CreateTableStmt:**

![CreateTableStmt](/media/sqlgram/CreateTableStmt.png)
![CreateTableLikeStmt](/media/sqlgram/CreateTableLikeStmt.png)

**LikeTableWithOrWithoutParen:**

![LikeTableWithOrWithoutParen](/media/sqlgram/LikeTableWithOrWithoutParen.png)

**TableName:**

![TableName](/media/sqlgram/TableName.png)

## Examples

```sql
Expand Down Expand Up @@ -52,6 +48,10 @@ mysql> SELECT * FROM t2;
Empty set (0.00 sec)
```

## Pre-split region

If the table to be copied is defined with the `PRE_SPLIT_REGIONS` attribute, the table created using the `CREATE TABLE LIKE` statement inherits this attribute, and the Region on the new table will be split. For details of `PRE_SPLIT_REGIONS`, see [`CREATE TABLE` Statement](/sql-statements/sql-statement-create-table.md).

## MySQL compatibility

This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](/report-issue.md) on GitHub.
Expand Down
51 changes: 36 additions & 15 deletions sql-statements/sql-statement-create-table.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,49 @@ This statement creates a new table in the currently selected database. See also

![TableElementListOpt](/media/sqlgram/TableElementListOpt.png)

**TableElement:**
**TableElementList:**

![TableElement](/media/sqlgram/TableElement.png)
![TableElementList](/media/sqlgram/TableElementList.png)

**PartitionOpt:**
**TableElement:**

![PartitionOpt](/media/sqlgram/PartitionOpt.png)
![TableElement](/media/sqlgram/TableElement.png)

**ColumnDef:**

![ColumnDef](/media/sqlgram/ColumnDef.png)

**ColumnName:**
**ColumnOptionListOpt:**

![ColumnName](/media/sqlgram/ColumnName.png)
![ColumnOptionListOpt](/media/sqlgram/ColumnOptionListOpt.png)

**Type:**
**ColumnOptionList:**

![Type](/media/sqlgram/Type.png)
![ColumnOptionList](/media/sqlgram/ColumnOptionList.png)

**ColumnOptionListOpt:**
**ColumnOption:**

![ColumnOptionListOpt](/media/sqlgram/ColumnOptionListOpt.png)
![ColumnOption](/media/sqlgram/ColumnOption.png)

**CreateTableOptionListOpt:**

![CreateTableOptionListOpt](/media/sqlgram/CreateTableOptionListOpt.png)

**PartitionOpt:**

![PartitionOpt](/media/sqlgram/PartitionOpt.png)

**DuplicateOpt:**

![DuplicateOpt](/media/sqlgram/DuplicateOpt.png)

**TableOptionList:**

![TableOptionList](/media/sqlgram/TableOptionList.png)

**TableOptionListOpt:**
**TableOption:**

![TableOptionListOpt](/media/sqlgram/TableOptionListOpt.png)
![TableOption](/media/sqlgram/TableOption.png)

## Syntax

Expand Down Expand Up @@ -215,10 +231,14 @@ The `table_option` currently only supports `AUTO_INCREMENT`, `SHARD_ROW_ID_BITS`
| `AUTO_INCREMENT` | The initial value of the increment field | `AUTO_INCREMENT` = 5 |
|`SHARD_ROW_ID_BITS`| To set the number of bits for the implicit `_tidb_rowid` shards |`SHARD_ROW_ID_BITS` = 4|
|`PRE_SPLIT_REGIONS`| To pre-split `2^(PRE_SPLIT_REGIONS)` Regions when creating a table |`PRE_SPLIT_REGIONS` = 4|
|`AUTO_ID_CACHE`| To set the auto ID cache size in a TiDB instance. By default, TiDB automatically changes this size according to allocation speed of auto ID |`AUTO_ID_CACHE` = 200|
|`AUTO_RANDOM_BASE`| To set the initial incremental part value of auto_random. This option can be considered as a part of the internal interface. Users can ignore this parameter |`AUTO_RANDOM_BASE` = 0|
| `CHARACTER SET` | To specify the string code for the table; currently only support UTF8MB4 | `CHARACTER SET` = 'utf8mb4' |
| `COMMENT` | The comment information | `COMMENT` = 'comment info' |

The `split-table` configuration option is enabled by default. When it is enabled, a separate Region is created for each newly created table.
> **Note:**
>
> The `split-table` configuration option is enabled by default. When it is enabled, a separate Region is created for each newly created table. For details, see [TiDB configuration file](/tidb-configuration-file.md).

## Examples

Expand Down Expand Up @@ -251,14 +271,15 @@ mysql> SELECT * FROM t1;

## MySQL compatibility

* TiDB does not support the syntax `CREATE TEMPORARY TABLE`.
* TiDB does not support temporary tables, but it ignores the `CREATE TEMPORARY TABLE` syntax.
* All of the data types except spatial types are supported.
* `FULLTEXT`, `HASH` and `SPATIAL` indexes are not supported.
* The `KEY_BLOCK_SIZE` and `ENGINE` attributes are parsed but ignored.
* The `index_col_name` attribute supports the length option with a maximum length limit of 3072 bytes. The length limit does not change depending on the storage engine, and character set used when building the table.
* The `index_col_name` attribute supports the length option with a maximum length limit of 3072 bytes by default. The length limit can be changed through the `max-index-length` configuration option. For details, see [TiDB configuration file](/tidb-configuration-file.md#max-index-length).
* The `index_col_name` attribute supports the index sorting options of `ASC` and `DESC`
* The `COMMENT` attribute supports a maximum of 1024 characters and does not support the `WITH PARSER` option.
* TiDB supports at most 512 columns in a single table. The corresponding number limit in InnoDB is 1017, and the hard limit in MySQL is 4096.
* For partitioned tables, only Range, Hash and Range Columns (single column) are supported. For details, see [partitoned table](/partitioned-table.md).

## See also

Expand Down