Skip to content

Commit

Permalink
docs: add drop table to reference (#974)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicecui committed May 22, 2024
1 parent f8c01cb commit 3091180
Show file tree
Hide file tree
Showing 16 changed files with 173 additions and 19 deletions.
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
57 changes: 57 additions & 0 deletions docs/nightly/en/reference/sql/drop.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# DROP

## DROP DATABASE

`DROP DATABASE` drops a database. It removes the catalog entries for the database and deletes the directory containing the data.

:::danger Danger

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

:::

### Syntax

```sql
DROP DATABASE [ IF EXISTS ] db_name
```

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

### 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
```

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


### Examples

Drop the table `monitor` in the current database:

```sql
DROP TABLE monitor;
```
1 change: 1 addition & 0 deletions docs/nightly/en/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
2 changes: 1 addition & 1 deletion docs/nightly/zh/getting-started/installation/overview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 概览
# 概述

- [GreptimeDB 单机模式](greptimedb-standalone.md)
- [GreptimeDB 分布式集群](greptimedb-cluster.md)
2 changes: 1 addition & 1 deletion docs/nightly/zh/getting-started/overview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 概览
# 概述

立即开始使用 GreptimeDB!

Expand Down
2 changes: 1 addition & 1 deletion docs/nightly/zh/getting-started/quick-start/overview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 概览
# 概述

使用你熟悉的协议或语言快速上手 GreptimeDB!
在这些文档中,我们将以 CPU 使用率为例,快速地感受 GreptimeDB 的基本用法。
Expand Down
2 changes: 1 addition & 1 deletion docs/nightly/zh/greptimecloud/usage-&-billing/overview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 概览
# 概述

此文档将帮助你了解 GreptimeCloud 的用量和费用。

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

## DROP DATABASE

`DROP DATABASE` 用于删除数据库,它删除数据库的目录项并删除包含数据的目录。

:::danger 危险操作

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

:::

### 语法

```sql
DROP DATABASE [ IF EXISTS ] db_name
```

- `IF EXISTS`: 如果数据库不存在,则不抛出错误。
- `db_name`: 要删除的数据库的名称。

### 示例

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

```sql
DROP DATABASE test;
```

## DROP TABLE

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

:::danger 危险操作

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

:::

### 语法

```sql
DROP TABLE [ IF EXISTS ] table_name
```

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

### 示例

删除 `monitor` 表:

```sql
DROP TABLE monitor;
```
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

0 comments on commit 3091180

Please sign in to comment.