Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add drop table to reference #974

Merged
merged 7 commits into from
May 22, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
3 changes: 2 additions & 1 deletion docs/nightly/en/faq-and-others/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ Currently, GreptimeDB's compatibility efforts are primarily focused on the imple

## Should I use the command "drop database" to delete a database?

Yes, that is the intended command. However, 'drop database' will be implemented in v0.8. It is expected to be included in the next minor iterative update. As a result, there is no direct way to delete a database at the moment. You may consider creating a new database for testing purposes. If you're working with test data, you also have the option to clear it by deleting the data directory.
Yes, you can use `DROP DATABASE db_name` command to delete a database.
Please refer to the [DROP](/reference/sql/drop.md#drop-database) document for more details.

## Are there any retention policy?

Expand Down
64 changes: 64 additions & 0 deletions docs/nightly/en/reference/sql/drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
# DROP

## DROP DATABASE

`DROP DATABASE` drops a database. It removes the catalog entries for the database and deletes the directory containing the data.
It cannot be executed while you are connected to the target database.
Also, if anyone else is connected to the target database, this command will fail unless you use the `FORCE` option described below.
killme2008 marked this conversation as resolved.
Show resolved Hide resolved

:::danger danger

`DROP DATABASE` cannot be undone. Use it with care!

:::

### Syntax

```sql
DROP DATABASE [ IF EXISTS ] db_name [ [ WITH ] ( option [, ...] ) ]
nicecui marked this conversation as resolved.
Show resolved Hide resolved

where option can be:

FORCE
nicecui marked this conversation as resolved.
Show resolved Hide resolved
```

- `IF EXISTS`: Do not throw an error if the database does not exist.
- `db_name`: The name of the database to remove.
- `FORCE`: Terminate all sessions connected to the target database before dropping it.
nicecui marked this conversation as resolved.
Show resolved Hide resolved

### Examples

To drop a database named `test`:

```sql
DROP DATABASE test;
```


## DROP TABLE

`DROP TABLE` removes tables from the database. It will remove the table definition and all table data, indexes, rules, and constraints for that table.

:::danger danger

`DROP TABLE` cannot be undone. Use it with care!

:::

### Syntax

```sql
DROP TABLE [ IF EXISTS ] table_name [, ...]
nicecui marked this conversation as resolved.
Show resolved Hide resolved
```

- `IF EXISTS`: Do not throw an error if the table does not exist.
- `table_name`: The name of the table to remove.


### Examples

To destroy two tables, `monitor` and `system_metrics`:
nicecui marked this conversation as resolved.
Show resolved Hide resolved

```sql
DROP TABLE monitor, system_metrics;
nicecui marked this conversation as resolved.
Show resolved Hide resolved
```
1 change: 1 addition & 0 deletions docs/nightly/en/summary.yml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ZH's summary.yml should be updated also?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No. Only the directory name needs to be updated in the zh summary.yml.

Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@
- insert
- cast
- copy
- drop
- select
- distinct
- where
Expand Down
2 changes: 1 addition & 1 deletion docs/nightly/en/user-guide/concepts/data-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ Those are very similar to the table model everyone is familiar with. The differe
These columns contain the actual data and are not indexed, but they can be efficiently computed and evaluated, such as the latest value, maximum/minimum value, average, percentage, and so on. Please avoid using `Field` columns in query conditions,
which is highly resource-intensive and unperformant.

To learn how to indicate `Tag`, `Timestamp`, and `Field` columns, Please refer to [table management](../table-management.md#create-table) and [CREATE statement](/reference/sql/create.md).
To learn how to indicate `Tag`, `Timestamp`, and `Field` columns, Please refer to [table management](../table-management.md#create-a-table) and [CREATE statement](/reference/sql/create.md).

## Design Considerations

Expand Down
4 changes: 2 additions & 2 deletions docs/nightly/en/user-guide/query-data/sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ GreptimeDB supports full SQL for querying data from a database.

In this document, we will use the `monitor` table to demonstrate how to query data.
For instructions on creating the `monitor` table and inserting data into it,
Please refer to [table management](/user-guide/table-management.md#create-table) and [write data](/user-guide/write-data/sql.md).
Please refer to [table management](/user-guide/table-management.md#create-a-table) and [write data](/user-guide/write-data/sql.md).

## Basic query

Expand Down Expand Up @@ -257,7 +257,7 @@ SELECT DISTINCT ON (host) * FROM monitor ORDER BY host, ts DESC;

GreptimeDB supports [Range Query](/reference/sql/range.md) to aggregate data by time window.

Suppose we have the following data in the [`monitor` table](../table-management.md#create-table):
Suppose we have the following data in the [`monitor` table](../table-management.md#create-a-table):

```sql
+-----------+---------------------+------+--------+
Expand Down
33 changes: 27 additions & 6 deletions docs/nightly/en/user-guide/table-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ uses [MySQL Command-Line Client](https://dev.mysql.com/doc/refman/8.0/en/mysql.h

For more explanations of the `SQL` syntax, please see the [SQL reference](/reference/sql/overview.md).

## Create Database
## Create a database

The default database is `public`. You can create a database manually.

Expand Down Expand Up @@ -62,7 +62,7 @@ Change back to `public` database:
USE public;
```

## Create Table
## Create a table

:::tip NOTE
GreptimeDB offers a schemaless approach to writing data that eliminates the need to manually create tables using additional protocols. See [Automatic Schema Generation](/user-guide/write-data/overview.md#automatic-schema-generation).
Expand Down Expand Up @@ -107,7 +107,7 @@ Therefore, it is important to carefully design your data model before creating t
[1]: https://docs.influxdata.com/influxdb/v1.8/concepts/glossary/#tag-key
[2]: https://docs.influxdata.com/influxdb/v1/concepts/glossary/#series

## Describe Table
## Describe a table

Show table information in detail:

Expand Down Expand Up @@ -178,7 +178,7 @@ SHOW TABLES FROM test;
1 row in set (0.01 sec)
```

## Alter Table
## Alter a table

You can alter the schema of existing tables just like in MySQL database

Expand All @@ -200,7 +200,11 @@ Query OK, 0 rows affected (0.03 sec)

Notice: currently only adding/dropping columns is allowed, altering column definition will soon be supported.

## Drop Table
## Drop a table

:::danger danger
`DROP TABLE` cannot be undone. Use it with care!
:::

`DROP TABLE [db.]table` is used to drop the table in `db` or the current database in-use.Drop the table `test` in the current database:

Expand All @@ -212,9 +216,26 @@ DROP TABLE monitor;
Query OK, 1 row affected (0.01 sec)
```

## Drop a database

:::danger danger
`DROP DATABASE` cannot be undone. Use it with care!
:::

You can use `DROP DATABASE` to drop a database.
For example, to drop the `test` database:

```sql
DROP DATABASE test;
```

Please refer to the [DROP](/reference/sql/drop.md#drop-database) document for more details.

## HTTP API

Using the following code to create a table through POST method:
You can execute the SQL statements through the HTTP API.
For example,
using the following code to create a table through POST method:

```shell
curl -X POST \
Expand Down
2 changes: 1 addition & 1 deletion docs/nightly/en/user-guide/write-data/prometheus.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Be sure to uncomment `basic_auth` section and replace `greptime_user(username)`,

The `db` parameter in the URL represents the database that we want to write data. It's optional.
By default, the database is `public`.
If you want to write to another database, you can [create a new database](../table-management.md#create-database)
If you want to write to another database, you can [create a new database](../table-management.md#create-a-database)
and replace `public` with the new database name.

GreptimeDB automatically groups multiple Prometheus metrics (../clients/prometheus#data-model) into the corresponding logical tables, so you do not need to specify the logical table in the URL of `remote_write`.
Expand Down
4 changes: 2 additions & 2 deletions docs/nightly/en/user-guide/write-data/sql.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

We will use the `monitor` table as an example to show how to write data.
For the SQL example on how to create the `monitor` table,
Please refer to [table management](../table-management.md#create-table).
Please refer to [table management](../table-management.md#create-a-table).

## Insert data

Expand Down Expand Up @@ -71,7 +71,7 @@ VALUES
("127.0.0.1", 1702433141000, 0.8, 0.1);
```

As described in the [Create Table](../table-management.md#create-table) section,
As described in the [Create Table](../table-management.md#create-a-table) section,
the `host` column represents the tag and the `ts` column represents the time index.
To update the data, you can use the same `host` and `ts` values as the existing data
and set the new `cpu` value to `0.5`:
Expand Down
62 changes: 62 additions & 0 deletions docs/nightly/zh/reference/sql/drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# DROP

## DROP DATABASE

`DROP DATABASE` 用于删除数据库,它删除数据库的目录项并删除包含数据的目录。
当你正在连接到目标数据库时无法执行该命令。
如果有其他人正在连接到目标数据库,需要使用下方描述的 `FORCE` 选项强制删除。

:::danger 危险操作

`DROP DATABASE` 无法撤消。请谨慎使用!

:::

### 语法

```sql
DROP DATABASE [ IF EXISTS ] db_name [ [ WITH ] ( option [, ...] ) ]
nicecui marked this conversation as resolved.
Show resolved Hide resolved

where option can be:

FORCE
nicecui marked this conversation as resolved.
Show resolved Hide resolved
```

- `IF EXISTS`: 如果数据库不存在,则不抛出错误。
- `db_name`: 要删除的数据库的名称。
- `FORCE`: 在删除数据库之前终止所有连接到目标数据库的会话。
nicecui marked this conversation as resolved.
Show resolved Hide resolved

### 示例

删除名为 `test` 的数据库:

```sql
DROP DATABASE test;
```

## DROP TABLE

`DROP TABLE` 从数据库中删除表,它将删除该表的表定义和所有表数据、索引、规则和约束。

:::danger 危险操作

`DROP TABLE` 无法撤消。请谨慎使用!

:::

### 语法

```sql
DROP TABLE [ IF EXISTS ] table_name [, ...]
nicecui marked this conversation as resolved.
Show resolved Hide resolved
```

- `IF EXISTS`: 如果表不存在,则不抛出错误。
- `table_name`: 要删除的表的名称。

### 示例

删除表 `monitor` 和 `system_metrics`:
nicecui marked this conversation as resolved.
Show resolved Hide resolved

```sql
DROP TABLE monitor, system_metrics;
nicecui marked this conversation as resolved.
Show resolved Hide resolved
```
2 changes: 1 addition & 1 deletion docs/nightly/zh/user-guide/concepts/data-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ GreptimeDB 中的所有数据都被组织成表,每个表中的数据项由三
- `Field` 列中的 `cpu_util`、`memory_util`、`disk_util` 和 `load` 列分别表示机器的 CPU 利用率、内存利用率、磁盘利用率和负载。
这些列包含实际的数据并且不被索引。应当避免在查询条件中使用 `Field` 列,这会消耗大量资源并且性能较差。

要了解如何指定 `Tag`、`Timestamp` 和 `Field` 列,请参见[表管理](../table-management.md#create-table)和 [CREATE 语句](/reference/sql/create.md)。
要了解如何指定 `Tag`、`Timestamp` 和 `Field` 列,请参见[表管理](../table-management.md#创建表)和 [CREATE 语句](/reference/sql/create.md)。

## 设计考虑

Expand Down
19 changes: 19 additions & 0 deletions docs/nightly/zh/user-guide/table-management.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,10 @@ Query OK, 0 rows affected (0.03 sec)

## 删除表

:::danger 危险操作
表删除后不可撤销!请谨慎操作!
:::

`DROP TABLE [db.]table` 用于删除 `db` 或当前正在使用的数据库中的表。

删除当前数据库中的表 `test`:
Expand All @@ -211,6 +215,21 @@ DROP TABLE monitor;
Query OK, 1 row affected (0.01 sec)
```

## 删除数据库

:::danger 危险操作
数据库删除后不可撤销!请谨慎操作!
:::

可以使用 `DROP DATABASE` 删除数据库。
例如,删除 `test` 数据库:

```sql
DROP DATABASE test;
```

请前往 [DROP](/reference/sql/drop.md#drop-database) 文档了解更多内容。

## HTTP API

使用以下代码,通过 POST 方法创建一个表:
Expand Down
2 changes: 1 addition & 1 deletion docs/nightly/zh/user-guide/write-data/prometheus.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ remote_read:
:::

URL 中的 `db` 参数表示我们要写入的数据库,是可选的,默认为 `public`。
如果你想要写入到其他数据库,可以[创建新数据库](../table-management.md#create-database)并将 `public` 替换为新的数据库名称。
如果你想要写入到其他数据库,可以[创建新数据库](../table-management.md#create-a-database)并将 `public` 替换为新的数据库名称。

GreptimeDB 将多个 Prometheus 指标[自动组合](../clients/prometheus#数据模型)到相应的逻辑表中,因此你无需在 `remote_write` 的 URL 中指定逻辑表。

Expand Down