Bu sayfa henüz yerel dilinizde mevcut değildir. Daha fazla dil seçeneği eklemek için yoğun bir şekilde çalışıyoruz. Desteğiniz için teşekkür ederiz.

Compute
Elastic Cloud Server
Huawei Cloud Flexus
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Cloud Phone Host
Huawei Cloud EulerOS
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
VPC Endpoint
Cloud Connect
Enterprise Router
Enterprise Switch
Global Accelerator
Management & Governance
Cloud Eye
Identity and Access Management
Cloud Trace Service
Resource Formation Service
Tag Management Service
Log Tank Service
Config
OneAccess
Resource Access Manager
Simple Message Notification
Application Performance Management
Application Operations Management
Organizations
Optimization Advisor
IAM Identity Center
Cloud Operations Center
Resource Governance Center
Migration
Server Migration Service
Object Storage Migration Service
Cloud Data Migration
Migration Center
Cloud Ecosystem
KooGallery
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP Filing
Support Plans
My Credentials
Customer Operation Capabilities
Partner Support Plans
Professional Services
Analytics
MapReduce Service
Data Lake Insight
CloudTable Service
Cloud Search Service
Data Lake Visualization
Data Ingestion Service
GaussDB(DWS)
DataArts Studio
Data Lake Factory
DataArts Lake Formation
IoT
IoT Device Access
Others
Product Pricing Details
System Permissions
Console Quick Start
Common FAQs
Instructions for Associating with a HUAWEI CLOUD Partner
Message Center
Security & Compliance
Security Technologies and Applications
Web Application Firewall
Host Security Service
Cloud Firewall
SecMaster
Anti-DDoS Service
Data Encryption Workshop
Database Security Service
Cloud Bastion Host
Data Security Center
Cloud Certificate Manager
Edge Security
Managed Threat Detection
Blockchain
Blockchain Service
Web3 Node Engine Service
Media Services
Media Processing Center
Video On Demand
Live
SparkRTC
MetaStudio
Storage
Object Storage Service
Elastic Volume Service
Cloud Backup and Recovery
Storage Disaster Recovery Service
Scalable File Service Turbo
Scalable File Service
Volume Backup Service
Cloud Server Backup Service
Data Express Service
Dedicated Distributed Storage Service
Containers
Cloud Container Engine
SoftWare Repository for Container
Application Service Mesh
Ubiquitous Cloud Native Service
Cloud Container Instance
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GeminiDB
GaussDB
Distributed Database Middleware
Database and Application Migration UGO
TaurusDB
Middleware
Distributed Cache Service
API Gateway
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
Multi-Site High Availability Service
EventGrid
Dedicated Cloud
Dedicated Computing Cluster
Business Applications
Workspace
ROMA Connect
Message & SMS
Domain Name Service
Edge Data Center Management
Meeting
AI
Face Recognition Service
Graph Engine Service
Content Moderation
Image Recognition
Optical Character Recognition
ModelArts
ImageSearch
Conversational Bot Service
Speech Interaction Service
Huawei HiLens
Video Intelligent Analysis Service
Developer Tools
SDK Developer Guide
API Request Signing Guide
Terraform
Koo Command Line Interface
Content Delivery & Edge Computing
Content Delivery Network
Intelligent EdgeFabric
CloudPond
Intelligent EdgeCloud
Solutions
SAP Cloud
High Performance Computing
Developer Services
ServiceStage
CodeArts
CodeArts PerfTest
CodeArts Req
CodeArts Pipeline
CodeArts Build
CodeArts Deploy
CodeArts Artifact
CodeArts TestPlan
CodeArts Check
CodeArts Repo
Cloud Application Engine
MacroVerse aPaaS
KooMessage
KooPhone
KooDrive
On this page

Show all

Common SQL DDL Clauses

Updated on 2024-12-06 GMT+08:00

This chapter describes common compatible SQL DDL clauses, including allocate_extent_clause, constraint, deallocate_unused_clause, file_specification, logging_clause, parallel_clause, physical_attributes_clause, size_clause, storage_clause, and aggregate function nesting. For details, see Table 1.

Table 1 Common SQL DDL clauses

No.

Oracle Database

GaussDB

Difference

1

allocate_extent_clause

Syntax:

ALLOCATE EXTENT   [ ( { SIZE size_clause       | DATAFILE 'filename'       | INSTANCE integer       } ...     )   ]

For example, after the employees table is created, change the allocated extent size of the table to 10M.

SQL> CREATE TABLE employees(EMPLOYEE_ID  NUMBER(38), JOB_ID NUMBER(38),  SALARY NUMBER(38),  LAST_NAME VARCHAR2(16));

Table created.

SQL> ALTER TABLE employees ALLOCATE EXTENT (SIZE 10M);

Table altered.

Not supported.

-

2

constraint

Syntax:

{ inline_constraint | out_of_line_constraint | inline_ref_constraint | out_of_line_ref_constraint }

For example, when you create the staff table, the ID and NAME columns specified in the constraint clause cannot be empty.

SQL> CREATE TABLE staff(ID INT NOT NULL, NAME char(8) NOT NULL, AGE INT, ADDRESS CHAR(50), SALARY REAL);

Table created.

Supported.

-

3

deallocate_unused_clause

Syntax:

DEALLOCATE UNUSED [ KEEP size_clause ]

For example, after creating the employees table and performing some INSERT and DELETE operations, you want to use the deallocate_unused_clause to release the unused space of the employees table.

SQL> CREATE TABLE employees(EMPLOYEE_ID  NUMBER(38), JOB_ID NUMBER(38),  SALARY NUMBER(38),  LAST_NAME VARCHAR2(16));

Table created.

- Perform some INSERT and DELETE operations.

SQL> ALTER TABLE employees DEALLOCATE UNUSED;

Table altered.

Not supported.

-

4

file_specification

Syntax:

{[ 'filename' | 'ASM_filename' ] [ SIZE size_clause ] [ REUSE ] [ autoextend_clause ]} 
|
{[ 'filename | ASM_filename' | ('filename | ASM_filename'    [, 'filename | ASM_filename' ]...) ] [ SIZE size_clause ] [ BLOCKSIZE size_clause [ REUSE ]}

For example, to create a temporary tablespace tbs_temp_01, the file_specification clause of the SQL statement specifies that a temporary database file templ01.dbf is created in the tablespace. The tablespace can be automatically expanded and allocated to the tablespace group tbs_grp_01.

SQL> CREATE TEMPORARY TABLESPACE tbs_temp_01 TEMPFILE 'temp01.dbf' AUTOEXTEND ON TABLESPACE GROUP tbs_grp_01;

Tablespace created.

Not supported.

-

5

logging_clause

Syntax:

{ LOGGING | NOLOGGING |  FILESYSTEM_LIKE_LOGGING }

Partially supported, with differences.

  • GaussDB does not support the LOGGING and FILESYSTEM_LIKE_LOGGING constraint clauses.

    Example:

    When a table is created in GaussDB with the LOGGING constraint clause, a syntax error is reported.

    gaussdb=# CREATE LOGGING TABLE my_tab(id int, name char(16));
    ERROR:  syntax error at or near "LOGGING"
    LINE 1: CREATE LOGGING TABLE my_tab(id int, name char(16));
                   ^

    When a table is created in GaussDB with the FILESYSTEM_LIKE_LOGGING constraint clause, a syntax error is reported.

    gaussdb=# CREATE FILESYSTEM_LIKE_LOGGING TABLE my_tab(id int, name char(16));
    ERROR:  syntax error at or near "FILESYSTEM_LIKE_LOGGING"
    LINE 1: CREATE FILESYSTEM_LIKE_LOGGING TABLE my_tab(id int, name cha...
                   ^
  • GaussDB supports only table-level UNLOGGED constraints and does not support column-level UNLOGGED constraints.

    For example, when a table is created in GaussDB with the column-level UNLOGGED constraint clause, a syntax error is reported.

    gaussdb=# CREATE UNLOGGED TABLE my_tab(id int UNLOGGED, name char(16));
    ERROR:  syntax error at or near "UNLOGGED"
    LINE 1: CREATE UNLOGGED TABLE my_tab(id int UNLOGGED, name char(16))...
                                                ^
  • GaussDB uses logging clauses only in the CREATE TABLE, CREATE TABLE AS, and SELECT INTO statements.

    For example, when a TABLESPACE statement with the UNLOGGED constraint clause is created in GaussDB, a syntax error is reported.

    gaussdb=# CREATE UNLOGGED TABLESPACE tbs1 RELATIVE LOCATION 'tablespace1/tablespace_1';
    ERROR:  syntax error at or near "TABLESPACE"
    LINE 1: CREATE UNLOGGED TABLESPACE tbs1 RELATIVE LOCATION 'tablespac...
                            ^

6

parallel_clause

Syntax:

{ NOPARALLEL | PARALLEL [ integer ] }

For example, if you create table t1 and specify PARALLEL 4 in the parallel_clause, a maximum of four parallel processes can be used to query and update table t1.

SQL> CREATE TABLE t1 (id NUMBER, name VARCHAR2(50)) PARALLEL 4;

Table created.

Not supported.

-

7

physical_attributes_clause

Syntax:

[ { PCTFREE integer   | PCTUSED integer   | INITRANS integer   | storage_clause   }... ]

Partially supported, with differences.

  • GaussDB does not support PCTUSED.

    For example, if you run an SQL statement to create the tbl1_ind index in the tbl1 table and set the space usage PCTUSED of the index to 20% in the physical_attributes_clause of the statement, an error is reported when the SQL statement is executed in GaussDB.

    gaussdb=# CREATE INDEX tbl1_ind ON tbl1 (name) PCTUSED 20;
    ERROR:  syntax error at or near "PCTUSED"
    LINE 1: CREATE INDEX tbl1_ind ON tbl1 (name) PCTUSED 20;
                                                 ^
  • GaussDB uses physical_attributes_clause only in the CREATE TABLE and CREATE INDEX statements.

    For example, if you run an SQL statement to obtain data from the tbl1 table, create the materialized view tbl1_mv, and set the number of initial transactions of the view to 30 in the physical_attributes_clause, an error is reported when GaussDB executes the statement.

    gaussdb=# CREATE MATERIALIZED VIEW tbl1_mv INITRANS 30 as select * from tbl1;
    ERROR:  syntax error at or near "INITRANS"
    LINE 1: CREATE MATERIALIZED VIEW tbl1_mv INITRANS 30 as select * fro...
                                             ^

8

size_clause

Syntax:

integer [ K | M | G | T | P | E ]

For example, create a temporary tablespace tbs_temp_01 and a temporary database file templ01.dbf in the tablespace. The initial size of the tablespace is 5M as specified by the size_clause in the SQL statement, which can be automatically expanded. The tablespace can be allocated to the tablespace group tbs_grp_01.

SQL> CREATE TEMPORARY TABLESPACE tbs_temp_01 TEMPFILE 'temp01.dbf' SIZE 5M AUTOEXTEND ON TABLESPACE GROUP tbs_grp_01;

Tablespace created.

Not supported.

-

9

storage_clause

Syntax:

STORAGE ({ INITIAL size_clause  | NEXT size_clause  | MINEXTENTS integer  | MAXEXTENTS { integer | UNLIMITED }  | maxsize_clause  | PCTINCREASE integer  | FREELISTS integer  | FREELIST GROUPS integer  | OPTIMAL [ size_clause | NULL ]  | BUFFER_POOL { KEEP | RECYCLE | DEFAULT }  | FLASH_CACHE { KEEP | NONE | DEFAULT }   | ( CELL_FLASH_CACHE ( KEEP | NONE | DEFAULT ) )  | ENCRYPT  } ... )

Partially supported, with differences.

  • In Oracle Database, storage parameters are specified by the STORAGE clause. In GaussDB, storage parameters are specified by the WITH clause.

    Example:

    To create the my_tab1 table in the Oracle Database, set the initial size of the table to 10M in the storage_clause, and add 5 MB each time when more space is required, run the following SQL statement:

    SQL> CREATE TABLE my_tab1 (id NUMBER(10) PRIMARY KEY, name VARCHAR2(50)) STORAGE (INITIAL 10M NEXT 5M);
    
    Table created.
    

    To create the my_tab2 table in GaussDB and set the storage engine type to ustore in the storage_clause, run the following SQL statement:

    gaussdb=# CREATE TABLE my_tab2 (id NUMBER(10) PRIMARY KEY, name VARCHAR2(50)) with (storage_type=ustore);
    NOTICE:  CREATE TABLE / PRIMARY KEY will create implicit index "my_tab2_pkey" for table "my_tab2"
    CREATE TABLE
  • Optional storage parameters in GaussDB are greatly different from those in Oracle Database. For details, see the GaussDB parameter description in "SQL Reference > SQL Syntax > C > CREATE TABLE" in Developer Guide. WITH ({storage_parameter = value} [, ...]) describes the storage parameters supported by the CREATE TABLE statement.

10

Aggregate function nesting

For example, create the revenue table generated by nesting the aggregate functions MIN() and SUM() in the sales_amount column of the sales table.

SQL> CREATE TABLE sales(ID INT, SALES_AMOUNT INT);

Table created.

SQL> INSERT INTO sales VALUES(1, 100);

1 row created.

SQL> INSERT INTO sales VALUES (3, 200);

1 row created.

SQL> CREATE TABLE revenue as SELECT SUM(MIN(sales_amount)) as total from sales group by sales_amount;

Table created.

Supported.

-

Sitemizi ve deneyiminizi iyileştirmek için çerezleri kullanırız. Sitemizde tarama yapmaya devam ederek çerez politikamızı kabul etmiş olursunuz. Daha fazla bilgi edinin

Feedback

Feedback

Feedback

0/500

Selected Content

Submit selected content with the feedback