Help Center > > Developer Guide> SQL Reference> DDL Syntax Overview

DDL Syntax Overview

Updated at:Aug 27, 2020 GMT+08:00

Data definition language (DDL) is used to define or modify an object in a database, such as a table, index, or view.

GaussDB(DWS) does not support DDL if its CN is unavailable. For example, if a CN in the cluster is faulty, creating a database or table will fail.

Defining a Database

A database is the warehouse for organizing, storing, and managing data. Defining a database includes: creating a database, altering the database attributes, and dropping the database. The following table lists the related SQL statements.

Table 1 SQL statements for defining a database

Function

SQL Statement

Create a database

CREATE DATABASE

Alter database attributes

ALTER DATABASE

Delete a database

DROP DATABASE

Defining a Schema

A schema is the set of a group of database objects and is used to control the access to the database objects. The following table lists the related SQL statements.

Table 2 SQL statements for defining a schema

Function

SQL Statement

Create a schema

CREATE SCHEMA

Alter schema attributes

ALTER SCHEMA

Delete a schema

DROP SCHEMA

Defining a Table

A table is a special data structure in a database and is used to store data objects and the relationship between data objects. The following table lists the related SQL statements.

Table 3 SQL statements for defining a table

Function

SQL Statement

Create a table

CREATE TABLE

Alter table attributes

ALTER TABLE

Delete a table

DROP TABLE

Defining a Partitioned Table

A partitioned table is a special data structure in a database and is used to store data objects and the relationship between data objects. The following table lists the related SQL statements.

Table 4 SQL statements for defining a partitioned table

Function

SQL Statement

Create a partitioned table

CREATE TABLE PARTITION

Create a partition

ALTER TABLE PARTITION

Alter partitioned table attributes

ALTER TABLE PARTITION

Delete a partition

ALTER TABLE PARTITION

Delete a partitioned table

DROP TABLE

Defining an Index

An index indicates the sequence of values in one or more columns in the database table. The database index is a data structure that improves the speed of data access to specific information in a database table. The following table lists the related SQL statements.

Table 5 SQL statements for defining an index

Function

SQL Statement

Create an index

CREATE INDEX

Alter index attributes

ALTER INDEX

Delete an index

DROP INDEX

Rebuild an index

REINDEX

Defining a Role

A role is used to manage rights. For database security, all management and operation rights can be assigned to different roles. The following table lists the related SQL statements.

Table 6 SQL statements for defining a role

Function

SQL Statement

Create a role

CREATE ROLE

Alter role attributes

ALTER ROLE

Delete a role

DROP ROLE

Defining a User

A user is used to log in to a database. Different rights can be assigned to users for managing data accesses and operations of users. The following table lists the related SQL statements.

Table 7 SQL statements for defining a user

Function

SQL Statement

Create a user

CREATE USER

Alter user attributes

ALTER USER

Delete a user

DROP USER

Defining a Stored Procedure

A stored procedure is a set of SQL statements for achieving specific functions and is stored in the database after compiling. Users can specify a name and provide parameters (if necessary) to execute the stored procedure. The following table lists the related SQL statements.

Table 8 SQL statements for defining a stored procedure

Function

SQL Statement

Create a stored procedure

CREATE PROCEDURE

Delete a stored procedure

DROP PROCEDURE

Define a Function

In GaussDB(DWS), a function is similar to a stored procedure, which is a set of SQL statements. The function and stored procedure are used the same. The following table lists the related SQL statements.

Table 9 SQL statements for defining a function

Function

SQL Statement

Create a function

CREATE FUNCTION

Alter function attributes

ALTER FUNCTION

Delete a function

DROP FUNCTION

Defining a View

A view is a virtual table exported from one or several basic tables. The view is used to control data accesses for users. The following table lists the related SQL statements.

Table 10 SQL statements for defining a view

Function

SQL Statement

Create a view

CREATE VIEW

Delete a view

DROP VIEW

Defining a Cursor

To process SQL statements, the stored procedure process assigns a memory segment to store context association. Cursors are handles or pointers to context regions. With a cursor, the stored procedure can control alterations in context areas.

Table 11 SQL statements for defining a cursor

Function

SQL Statement

Create a cursor

CURSOR

Move a cursor

MOVE

Extract data from a cursor

FETCH

Close a cursor

CLOSE

Altering or Ending a Session

A session is a connection established between the user and the database. The following table lists the related SQL statements.

Table 12 SQL statements related to sessions

Function

SQL Statement

Alter a session

ALTER SESSION

End a session

ALTER SYSTEM KILL SESSION

Defining a Resource Pool

A resource pool is a system catalog used by the resource load management module to specify attributes related to resource management, such as Cgroups. The following table lists the related SQL statements.

Table 13 SQL statements for defining a resource pool

Function

SQL Statement

Create a resource pool

CREATE RESOURCE POOL

Change resource attributes

ALTER RESOURCE POOL

Delete a resource pool

DROP RESOURCE POOL

Defining Synonyms

A synonym is a special database object compatible with Oracle. It is used to store the mapping between a database object and another. Currently, only synonyms can be used to associate the following database objects: tables, views, functions, and stored procedures. The following table lists the related SQL statements.

Table 14 SQL statements for defining a resource pool

Function

SQL Statement

Creating a synonym

4.18.14.66-CREATE SYNONYM

Modifying a synonym

4.18.14.23-ALTER SYNONYM

Deleting a synonym

4.18.14.101-DROP SYNONYM

Did you find this page helpful?

Submit successfully!

Thank you for your feedback. Your feedback helps make our documentation better.

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel