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

[Doc] Fix database related documentation #1927

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
93 changes: 42 additions & 51 deletions docs/sql-manual/sql-statements/database/ALTER-DATABASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,79 +27,70 @@ under the License.

## Description

This statement is used to set properties of the specified database. (administrator only)
This statement is used to set the properties of a specified db, change the db name, and set various quotas for the db.

1) Set the database data quota, the unit is B/K/KB/M/MB/G/GB/T/TB/P/PB
## Syntax

```sql
ALTER DATABASE db_name SET DATA QUOTA quota;
ALTER DATABASE <db_name> RENAME <new_name>
ALTER DATABASE <db_name> SET { DATA | REPLICA | TRANSACTION } QUOTA <quota>
ALTER DATABASE <db_name> SET <PROPERTIES> ("<key>" = "<value>" [, ...])
```

2) Rename the database
## Required parameters

```sql
ALTER DATABASE db_name RENAME new_db_name;
```
** 1. `<db_name>`**
> Database Name

3) Set the quota for the number of copies of the database
** 2. `<new_db_name>`**
> New database name

```sql
ALTER DATABASE db_name SET REPLICA QUOTA quota;
```
** 3. `<quota>`**
> Database data volume quota or database replica number quota

illustrate:
After renaming the database, use the REVOKE and GRANT commands to modify the appropriate user permissions, if necessary.
The default data quota for the database is 1024GB, and the default replica quota is 1073741824.
** 4. `<PROPERTIES>`**
> Additional information about this database

4) Modify the properties of an existing database
## Permission Control

```sql
ALTER DATABASE db_name SET PROPERTIES ("key"="value", ...);
```

## Example

1. Set the specified database data volume quota

```sql
ALTER DATABASE example_db SET DATA QUOTA 10995116277760;
The above unit is bytes, which is equivalent to
ALTER DATABASE example_db SET DATA QUOTA 10T;
The user executing this SQL command must have at least the following permissions:

ALTER DATABASE example_db SET DATA QUOTA 100G;
| Permissions | Object | Notes |
|:-----------|:-----|:--------------|
| ALTER_PRIV | Corresponding database | You need to have the permission to change the corresponding database. |

ALTER DATABASE example_db SET DATA QUOTA 200M;
```
## Precautions

2. Rename the database example_db to example_db2
After renaming the database, use the REVOKE and GRANT commands to modify the corresponding user permissions if necessary. The default data volume quota for a database is 1024 GB, and the default replica number quota is 1073741824.

```sql
ALTER DATABASE example_db RENAME example_db2;
```
## Example

3. Set the quota for the number of copies of the specified database
- Set the data volume quota for the specified database

```sql
ALTER DATABASE example_db SET REPLICA QUOTA 102400;
```
```sql
ALTER DATABASE example_db SET DATA QUOTA 10995116277760;
```

4. Modify the default replica distribution policy for tables in db (this operation only applies to newly created tables and will not modify existing tables in db)
- Rename the database example_db to example_db2

```sql
ALTER DATABASE example_db SET PROPERTIES("replication_allocation" = "tag.location.default:2");
```
```sql
ALTER DATABASE example_db RENAME example_db2;
```

5. Cancel the default replica distribution policy for tables in db (this operation only applies to newly created tables and will not modify existing tables in db)
- Set a quota for the number of copies of a specified database

```sql
ALTER DATABASE example_db SET PROPERTIES("replication_allocation" = "");
```
```sql
ALTER DATABASE example_db SET REPLICA QUOTA 102400;
```

## Keywords
- Modify the default replica distribution strategy of the table under db (this operation is only effective for newly created tables and will not modify existing tables under db)

```text
ALTER,DATABASE,RENAME
```
```sql
ALTER DATABASE example_db SET PROPERTIES("replication_allocation" = "tag.location.default:2");
```

## Best Practice
- Cancel the default replica distribution policy of the table under db (this operation is only effective for newly created tables and will not modify existing tables under db)

```sql
ALTER DATABASE example_db SET PROPERTIES("replication_allocation" = "");
```
52 changes: 29 additions & 23 deletions docs/sql-manual/sql-statements/database/CREATE-DATABASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,37 @@ under the License.

## Description

This statement is used to create a new database (database)
This statement is used to create a new database

grammar:
## Syntax

```sql
CREATE DATABASE [IF NOT EXISTS] db_name
[PROPERTIES ("key"="value", ...)];
CREATE DATABASE [IF NOT EXISTS] <db_name>
[PROPERTIES ("<key>"="<value>"[, ... ])];
```

`PROPERTIES` Additional information about the database, which can be defaulted.
## Required parameters

- If you want to specify the default replica distribution for tables in db, you need to specify `replication_allocation` (the `replication_allocation` attribute of table will have higher priority than db)
** 1. `<db_name>`**
> Database Name

## Optional parameters

** 1. `<PROPERTIES>`**
> Additional information about this database

## Permission Control

The user executing this SQL command must have at least the following permissions:

| Permissions | Object | Notes |
|:-----------|:------|:---------------|
| CREATE_PRIV | Corresponding database | You need to have the create permission for the corresponding database |


## Precautions

If you want to specify the default replica distribution strategy for the table under db, you need to specify `<replication_allocation>` (the `<replication_allocation>` attribute of table has a higher priority than db):

```sql
PROPERTIES (
Expand All @@ -48,30 +67,17 @@ CREATE DATABASE [IF NOT EXISTS] db_name

## Example

1. Create a new database db_test
- Create a new database db_test

```sql
CREATE DATABASE db_test;
```

2. Create a new database with default replica distribution:
- Create a new database and set the default replica distribution:

```sql
CREATE DATABASE `iceberg_test`
CREATE DATABASE `db_test`
PROPERTIES (
"replication_allocation" = "tag.location.group_1:3"
"replication_allocation" = "tag.location.group_1:3"
);
```

:::caution
If the create table statement has attributes replication_allocation or replication_num, then the default replica distribution policy of the database will not take effect.
:::

## Keywords

```text
CREATE, DATABASE
```

## Best Practice

43 changes: 28 additions & 15 deletions docs/sql-manual/sql-statements/database/DROP-DATABASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,28 +27,41 @@ under the License.

## Description

This statement is used to delete the database (database)
grammar:
This statement is used to delete a database.

## Syntax

```sql
DROP DATABASE [IF EXISTS] db_name [FORCE];
DROP DATABASE [IF EXISTS] <db_name> [FORCE];
```

illustrate:
## Required parameters

- During the execution of DROP DATABASE, the deleted database can be recovered through the RECOVER statement. See the [RECOVER](../../Database-Administration-Statements/RECOVER.md) statement for details
- If you execute DROP DATABASE FORCE, the system will not check the database for unfinished transactions, the database will be deleted directly and cannot be recovered, this operation is generally not recommended
** 1. `<db_name>`**
> Database Name

## Example
## Optional parameters

** 1. `FORCE`**
> Force deletion without going to the Recycle Bin

## Permission Control

The user executing this SQL command must have at least the following permissions:

1. Delete the database db_test

```sql
DROP DATABASE db_test;
```
| Permissions | Object | Notes |
|:-----------|:------|:---------------|
| DROP_PRIV | Corresponding database | You need to have delete permission on the corresponding database |

## Keywords

DROP, DATABASE
## Precautions

If you execute DROP DATABASE FORCE, the system will not check whether there are any unfinished transactions in the database. The database will be deleted directly and cannot be restored. This operation is generally not recommended.

## Example

- Deleting a Database db_test

## Best Practice
```sql
DROP DATABASE db_test;
```
88 changes: 53 additions & 35 deletions docs/sql-manual/sql-statements/database/SHOW-CREATE-DATABASE.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,47 +27,65 @@ under the License.

## Description

This statement checks the creation of the doris database, support database from both internal catalog and hms catalog
This statement checks the creation information of the doris built-in database or catalog database.

grammar:
## Syntax

```sql
SHOW CREATE DATABASE db_name;
SHOW CREATE DATABASE [<catalog>.]<db_name>;
```

illustrate:
## Required parameters

- `db_name`: The name of the database
- if specific a database from hms catalog, will return same with this stmt in hive
** 1. `<db_name>`**
> Database Name

## Optional parameters

** 1. `<catalog>`**
> Indicates whether the table is internal or external

## Return Value

| Column | Description |
|:---------|:-----------|
| Database | Database Name |
| Create Database | Corresponding database creation statement |

## Permission Control

The user executing this SQL command must have at least the following permissions:

| Permissions | Object | Notes |
|:-----------|:------|:---------------|
| SELECT_PRIV | Corresponding database | Requires read permission on the corresponding database |

## Example

1. View the creation of the test database in doris internal catalog

```sql
mysql> SHOW CREATE DATABASE test;
+----------+----------------------------+
| Database | Create Database |
+----------+----------------------------+
| test | CREATE DATABASE `test` |
+----------+----------------------------+
1 row in set (0.00 sec)
```

2. view a database named `hdfs_text` from a hms catalog

```sql
mysql> show create database hdfs_text;
+-----------+------------------------------------------------------------------------------------+
| Database | Create Database |
+-----------+------------------------------------------------------------------------------------+
| hdfs_text | CREATE DATABASE `hdfs_text` LOCATION 'hdfs://HDFS1009138/hive/warehouse/hdfs_text' |
+-----------+------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
```

## Keywords

SHOW, CREATE, DATABASE

## Best Practice
- View the creation of the test database in doris

```sql
SHOW CREATE DATABASE test;
```

```text
+----------+------------------------+
| Database | Create Database |
+----------+------------------------+
| test | CREATE DATABASE `test` |
+----------+------------------------+
```

- View the creation information of the database hdfs_text in the hive catalog

```sql
SHOW CREATE DATABASE hdfs_text;
```

```text
+-----------+------------------------------------------------------------------------------------+
| Database | Create Database |
+-----------+------------------------------------------------------------------------------------+
| hdfs_text | CREATE DATABASE `hdfs_text` LOCATION 'hdfs://HDFS1009138/hive/warehouse/hdfs_text' |
+-----------+------------------------------------------------------------------------------------+
```
Loading