Create Database
Function
Creates a database.
Syntax
CREATE [DATABASE | SCHEMA] [IF NOT EXISTS] db_name [COMMENT db_comment] LOCATION obs_path [WITH DBPROPERTIES (property_name=property_value, ...)];
Keywords
- IF NOT EXISTS: Does not raise an error if the database to be created already exists; silently skips.
- COMMENT: A description of the database.
- LOCATION: Specifies the storage path of the database in the file system. Must be specified and in OBS format, e.g., obs://bucket-name/db-path/. An error is reported if LOCATION is not specified or does not meet the format requirements.
- WITH DBPROPERTIES: Properties of the database, with property names and values appearing in pairs.
Parameters
| Parameter | Description |
|---|---|
| db_name | Database name. Only letters, digits, and underscores (_) are allowed. It cannot be purely numeric and cannot start with a digit or underscore. |
| db_comment | Database description. |
| obs_path | Database storage path, must be in obs:// format, pointing to a valid object storage path. |
| property_name | Database property name. |
| property_value | Database property value. |
Precautions
- DATABASE and SCHEMA have no difference and can be used interchangeably. DATABASE is recommended.
- default is a built-in database. A database named default cannot be created.
- Use DESCRIBE DATABASE EXTENDED to view database property information.
Example 1: Create a Database
Create database testdb. If testdb already exists, no error is raised.
CREATE DATABASE IF NOT EXISTS testdb LOCATION 'obs://my-bucket/testdb/';
Example 2: Create a Database with Comment and Properties
Create database customer_db with comment and property information.
CREATE DATABASE IF NOT EXISTS customer_db COMMENT 'This is customer database' LOCATION 'obs://my-bucket/customer_db/' WITH DBPROPERTIES (ID=001, Name='John');
Example 3: Verify Database Properties
Use DESCRIBE DATABASE EXTENDED to view detailed database information, including properties.
DESCRIBE DATABASE EXTENDED customer_db;
Example result:
| database_description_item | database_description_value |
|---|---|
| Database Name | customer_db |
| Description | This is customer database |
| Location | obs://my-bucket/customer_db/ |
| Properties | ((ID,001), (Name,John)) |
Example 4: Create a Database Using the SCHEMA Keyword
SCHEMA is equivalent to DATABASE and can be used interchangeably.
CREATE SCHEMA IF NOT EXISTS payroll_db LOCATION 'obs://my-bucket/payroll_db/';
What is your overall rating for this page?
Thank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot