|
1 | 1 | ---
|
2 |
| -title: Table |
| 2 | +title: Table Commands |
3 | 3 | ---
|
4 | 4 |
|
5 |
| -This page compiles crucial insights into table operations, serving as a comprehensive guide for you navigating the intricacies of working with tables in Databend. It strings together essential table-related commands to provide a cohesive understanding of key considerations in table management. |
6 |
| - |
7 |
| -## Table Creation Essentials |
8 |
| - |
9 |
| -It is a good idea to to familiarize yourself with the following topics before proceeding to create a table. |
10 |
| - |
11 |
| -### 1. Understanding Table Types |
12 |
| - |
13 |
| -Databend supports two types of tables based on their Time Travel support: |
14 |
| - |
15 |
| -- **General Tables (Default)**: These tables inherently support Time Travel, allowing you to trace and retrieve historical data. This feature is valuable for data analysis and auditing. |
16 |
| - |
17 |
| -- **Transient Tables**: In contrast, transient tables do not support Time Travel. They are designed for scenarios where historical data tracking is not necessary. To create a transient table, you must explicitly specify the keyword TRANSIENT in the [CREATE TABLE](10-ddl-create-table.md) command. For more information, see [CREATE TRANSIENT TABLE](10-ddl-create-table.md#create-transient-table). |
18 |
| - |
19 |
| -### 2. Selecting Table Storage |
20 |
| - |
21 |
| -Databend defaults to storing table data in the location configured in the [databend-query.toml](https://github.com/databendlabs/databend/blob/main/scripts/distribution/configs/databend-query.toml) configuration file. Additionally, it provides the flexibility to store table data in a different bucket, deviating from the default setting. For more information, see [CREATE TABLE ... EXTERNAL_LOCATION](10-ddl-create-table.md#create-table--external_location). |
22 |
| - |
23 |
| -### 3. Defining Table Structure |
24 |
| - |
25 |
| -The primary method to define columns in a table is through the [CREATE TABLE](10-ddl-create-table.md#create-table) command, where you list your columns one by one. Please note that Computed Columns are supported as an Enterprise Edition feature in Databend. For more information, see [Computed Columns](10-ddl-create-table.md#computed-columns). |
26 |
| - |
27 |
| -Databend also offers convenient methods for creating tables by copying column structures and even data from existing tables: |
28 |
| - |
29 |
| -- [CREATE TABLE ... LIKE](10-ddl-create-table.md#create-table--like): Creates a table with the same column definitions as an existing one. |
30 |
| -- [CREATE TABLE ... AS](10-ddl-create-table.md#create-table--as): Creates a table and inserts data based on the results of a SELECT query. |
31 |
| -- [ATTACH TABLE](92-attach-table.md): Creates a table by associating it with an existing table. |
32 |
| - |
33 |
| -### 4. Setting Cluster Key for Big Tables |
34 |
| - |
35 |
| -[Cluster Key](../06-clusterkey/index.md) is designed to enhance query performance by physically organizing data in proximity. Databend recommends configuring cluster keys, especially for large tables encountering sluggish query performance. For the syntax to set a cluster key during table creation, see [SET CLUSTER KEY](../06-clusterkey/dml-set-cluster-key.md). |
36 |
| - |
37 |
| -## Routine Table Maintenance |
38 |
| - |
39 |
| -Once your table is created, you gain the foundation for organizing and managing your data effectively. With this structure in place, you can seamlessly execute various commands to enhance, modify, or extract information from your table. Whether it's adjusting column properties, fine-tuning configurations, or querying data, Databend provides a versatile set of tools to meet your evolving needs. |
40 |
| - |
41 |
| -- [DESCRIBE TABLE](50-describe-table.md), [SHOW FIELDS](show-fields.md): Shows information about the columns in a given table. |
42 |
| -- [SHOW FULL COLUMNS](show-full-columns.md): Retrieves comprehensive details about the columns in a given table. |
43 |
| -- [SHOW CREATE TABLE](show-create-table.md): Shows the CREATE TABLE statement that creates the named table. |
44 |
| -- [SHOW DROP TABLES](show-drop-tables.md): Lists the dropped tables in the current or a specified database. |
45 |
| -- [SHOW TABLE STATUS](show-table-status.md): Shows the status of the tables in a database. |
46 |
| -- [SHOW TABLES](show-tables.md): Lists the tables in the current or a specified database. |
47 |
| -- [ALTER TABLE COLUMN](90-alter-table-column.md): Modifies the structure of a table by making changes to its columns. |
48 |
| -- [ALTER TABLE OPTION](90-alter-table-option.md): Modifies the Fuse engine [Options](../../../00-sql-reference/30-table-engines/00-fuse.md#options) of a table. |
49 |
| -- [RENAME TABLE](30-ddl-rename-table.md): Changes the name of a table. |
50 |
| - |
51 |
| -## Table Deletion & Recovery Strategies |
52 |
| - |
53 |
| -Databend provides a variety of commands for deleting a table or vacuuming the table data. The table below compares these commands, which may initially seem complex, outlining any associated recovery options for each operation. |
54 |
| - |
55 |
| -| Command | Enterprise Edition? | Description | Recovery | |
56 |
| -| -------------------------------------------- | ------------------- | ------------------------------------------------------------------ | ---------------------------------------- | |
57 |
| -| [TRUNCATE TABLE](40-ddl-truncate-table.md) | No | Removes all data from a table while preserving the table's schema. | [FLASHBACK TABLE](70-flashback-table.md) | |
58 |
| -| [DROP TABLE](20-ddl-drop-table.md) | No | Deletes a table. | [UNDROP TABLE](21-ddl-undrop-table.md) | |
59 |
| -| [VACUUM TABLE](91-vacuum-table.md) | Yes | Permanently removes historical data files of a table. | Not applicable. | |
60 |
| -| [VACUUM DROP TABLE](91-vacuum-drop-table.md) | Yes | Permanently removes data files of dropped tables. | Not applicable. | |
61 |
| - |
62 |
| -## Advanced Table Optimization Techniques |
63 |
| - |
64 |
| -Tables in Databend might need optimizations over time to ensure efficient performance and storage utilization. In this case, the following commands can help you out: |
| 5 | +This page provides a comprehensive overview of table operations in Databend, organized by functionality for easy reference. |
| 6 | + |
| 7 | +## Table Creation |
| 8 | + |
| 9 | +| Command | Description | |
| 10 | +|---------|-------------| |
| 11 | +| [CREATE TABLE](10-ddl-create-table.md) | Creates a new table with specified columns and options | |
| 12 | +| [CREATE TABLE ... LIKE](10-ddl-create-table.md#create-table--like) | Creates a table with the same column definitions as an existing one | |
| 13 | +| [CREATE TABLE ... AS](10-ddl-create-table.md#create-table--as) | Creates a table and inserts data based on the results of a SELECT query | |
| 14 | +| [CREATE TRANSIENT TABLE](10-ddl-create-transient-table.md) | Creates a table without Time Travel support | |
| 15 | +| [CREATE EXTERNAL TABLE](10-ddl-create-table-external-location.md) | Creates a table with data stored in a specified external location | |
| 16 | +| [ATTACH TABLE](92-attach-table.md) | Creates a table by associating it with an existing table | |
| 17 | + |
| 18 | +## Table Modification |
| 19 | + |
| 20 | +| Command | Description | |
| 21 | +|---------|-------------| |
| 22 | +| [ALTER TABLE COLUMN](90-alter-table-column.md) | Modifies the structure of a table by making changes to its columns | |
| 23 | +| [ALTER TABLE CONNECTION](91-alter-table-connection.md) | Updates the connection settings for an external table | |
| 24 | +| [ALTER TABLE OPTION](90-alter-table-option.md) | Modifies the Fuse engine options of a table | |
| 25 | +| [ALTER TABLE COMMENT](90-alter-table-comment.md) | Updates the comment for a table | |
| 26 | +| [RENAME TABLE](30-ddl-rename-table.md) | Changes the name of a table | |
| 27 | + |
| 28 | +## Table Information |
| 29 | + |
| 30 | +| Command | Description | |
| 31 | +|---------|-------------| |
| 32 | +| [DESCRIBE TABLE](50-describe-table.md) / [SHOW FIELDS](show-fields.md) | Shows information about the columns in a given table | |
| 33 | +| [SHOW FULL COLUMNS](show-full-columns.md) | Retrieves comprehensive details about the columns in a given table | |
| 34 | +| [SHOW CREATE TABLE](show-create-table.md) | Shows the CREATE TABLE statement that creates the named table | |
| 35 | +| [SHOW TABLES](show-tables.md) | Lists the tables in the current or a specified database | |
| 36 | +| [SHOW TABLE STATUS](show-table-status.md) | Shows the status of the tables in a database | |
| 37 | +| [SHOW DROP TABLES](show-drop-tables.md) | Lists the dropped tables in the current or a specified database | |
| 38 | + |
| 39 | +## Table Deletion & Recovery |
| 40 | + |
| 41 | +| Command | Description | Recovery Option | |
| 42 | +|---------|-------------|----------------| |
| 43 | +| [TRUNCATE TABLE](40-ddl-truncate-table.md) | Removes all data from a table while preserving the table's schema | [FLASHBACK TABLE](70-flashback-table.md) | |
| 44 | +| [DROP TABLE](20-ddl-drop-table.md) | Deletes a table | [UNDROP TABLE](21-ddl-undrop-table.md) | |
| 45 | +| [VACUUM TABLE](91-vacuum-table.md) | Permanently removes historical data files of a table (Enterprise Edition) | Not recoverable | |
| 46 | +| [VACUUM DROP TABLE](91-vacuum-drop-table.md) | Permanently removes data files of dropped tables (Enterprise Edition) | Not recoverable | |
| 47 | + |
| 48 | +## Table Optimization |
| 49 | + |
| 50 | +| Command | Description | |
| 51 | +|---------|-------------| |
| 52 | +| [ANALYZE TABLE](80-analyze-table.md) | Calculates table statistics to improve query performance | |
| 53 | +| [OPTIMIZE TABLE](60-optimize-table.md) | Compacts or purges historical data to save storage space and enhance query performance | |
| 54 | +| [SET CLUSTER KEY](../06-clusterkey/dml-set-cluster-key.md) | Configures a cluster key to enhance query performance for large tables | |
65 | 55 |
|
66 | 56 | :::note
|
67 |
| -Table Optimization is an advanced-level operation. Databend recommends carefully reading the links below and understanding the optimization process before proceeding to avoid potential data loss. |
| 57 | +Table optimization is an advanced operation. Please carefully read the documentation before proceeding to avoid potential data loss. |
68 | 58 | :::
|
69 |
| - |
70 |
| -- [ANALYZE TABLE](80-analyze-table.md): Calculates table statistics. |
71 |
| -- [OPTIMIZE TABLE](60-optimize-table.md): Involves compacting or purging historical data to save storage space and enhance query performance. |
0 commit comments