Data Definition Language (DDL)
Reference for the Data Definition Language (DDL) commands supported by GridGain 9, including CREATE, ALTER, and DROP for tables, indexes, schemas, caches, and sequences.
This section walks you through all data definition language (DDL) commands supported by GridGain 9.0.
CREATE TABLE
Creates a new table.
CREATE TABLE [IF NOT EXISTS] qualified_table_name
( { column_definition | constraint } [, ...] )
[COLOCATE [BY] ( column_list )]
[[PRIMARY] ZONE zone_name]
[[PRIMARY] STORAGE PROFILE profile_name]
[SECONDARY ZONE zone_name SECONDARY STORAGE PROFILE profile_name]
[{ EXPIRE AT expiry_column_name | ARCHIVE AT archive_column_name }]
[WITH ( paramName paramValue [, ...] )]Keywords and parameters:
IF NOT EXISTS- create the table only if a table with the same name does not exist.COLOCATE BY- colocation key. The key can be composite. Primary key must include colocation key.ZONE- sets the Distribution Zone. Can be preceded byPRIMARYto signify the primary distribution zone, or bySECONDARYto signify the secondary distribution zone. Can be specified as a case-sensitive string or case-insensitive identifier. Does not need to exist at the moment of table creation, and can be created before writing data.STORAGE PROFILE- sets the storage profile that will be used to store the table. Can be preceded byPRIMARYto signify the primary storage, or bySECONDARYto signify the secondary (columnar) storage profile. Must be specified as a case-sensitive string. Can be preceded byPRIMARYto signify the primary storage profile.EXPIRE AT- defines when a record should be deleted based on the provided point in time. UnlikeARCHIVE AT, deletes the data both in primary and secondary storage when the specified time is reached.ARCHIVE AT- defines when a record should be removed from primary storage based on the provided point in time. The data will still be available for reading in secondary storage. This condition comes with several limitations:You cannot use this condition without secondary storage. Table must have secondary storage attached.
You cannot use this condition together with
EXPIRE AT.After the
ARCHIVE ATtimestamp is reached, you cannot modify the archived data withUPDATEorDELETEoperations. Only the data that exists in the primary storage can be modified.
WITH- defines the list of additional table parameters. The following parameters are supported:min stale rows- number of updates since the last query plan update required to automatically recreate query execution plan. Overridesignite.sql.createTable.minStaleRowsCount. Default value is500.stale rows fraction- fraction of the table that must change for query execution plan to be recreated automatically. Overridesignite.sql.createTable.staleRowsFraction. Default value is0.2.row level security- enables (ON) or disables (OFF) row-level security on the table. If omitted, row-level security is disabled. This is equivalent to creating the table and then runningALTER TABLE ... SET ROW LEVEL SECURITY ON. Available only in GridGain 9 Enterprise and Ultimate editions; setting it requires theMANAGE_RLSprivilege on the table.
Examples:
Creates a Person table:
Creates a Person table that uses distribution zone exampleZone:
Creates a Person table that uses distribution zone myExampleZone that is specified as a case-sensitive string:
Creates a Person table that uses the default storage profile regardless of the storage profile specified in the distribution zone:
Creates a Person table that uses the secondary distribution zone and a secondary storage profile for columnar data:
Creates a Person table where the records expire at timestamps in the ttl column:
Creates a Person table where the default value if the city_id column is 1:
Creates a Person table where a random personal identifier is generated automatically:
Creates a Person table with the duration column automatically set a week into the future:
Archives old data while keeping it accessible in secondary storage:
Reads the archived data, explicitly using the secondary storage access hint:
Creates a Person table with row-level security enabled. The property can be combined with other table properties:
ALTER TABLE
Modifies the structure of an existing table.
ALTER TABLE IF EXISTS table ADD COLUMN (column1 int, column2 int)
Adds column(s) to an existing table.
Keywords and parameters:
IF EXISTS- do not throw an error if a table with the specified table name does not exist.IF NOT EXISTS- do not throw an error if a column with the specified column name already exists.
Examples:
Add a column to the table:
Add a column only if the table exists:
Add several columns to the table at once:
ALTER TABLE IF EXISTS table DROP COLUMN (column1, column2 int)
Removes column(s) from an existing table. Once a column is removed, it cannot be accessed within queries. This command has the following limitations:
If the column was indexed, the index has to be dropped manually in advance by using the 'DROP INDEX' command.
It is not possible to remove a column if it represents the whole value stored in the cluster. The limitation is relevant for primitive values.
Keywords and parameters:
IF EXISTS- do not throw an error if a table with the specified table name does not exist.
Examples:
Drop a column from the table:
Drop a column only if the table exists:
Drop several columns from the table at once:
ALTER TABLE IF EXISTS table ALTER COLUMN column SET DATA TYPE
Changes the data type for the column(s) in an existing table.
Keywords and parameters:
IF EXISTS- do not throw an error if a table with the specified table name does not exist.data_type- a valid data type.
Examples:
Alter a column in the table:
Supported Transitions
Not all data type transitions are supported. The limitations are listed below:
FLOATcan be transitioned toDOUBLEINT8,INT16andINT64can be transitioned toINT32TYPE SCALEchange is forbiddenTYPE PRECISIONincrease is allowed for DECIMAL non PK columnTYPE LENGTHincrease is allowed for STRING and BYTE_ARRAY non PK column
Other transitions are not supported.
Examples:
Changes the possible range of IDs to BIGINT ranges:
Sets the length of a column text to 11:
ALTER TABLE IF EXISTS table ALTER COLUMN column SET NOT NULL
Keywords and parameters:
IF EXISTS- do not throw an error if a table with the specified table name does not exist.
Supported Transitions
Not all data type transitions are supported. The limitations are listed below:
NULLABLEtoNOT NULLtransition is forbidden
ALTER TABLE IF EXISTS table ALTER COLUMN column DROP NOT NULL
Keywords and parameters:
IF EXISTS- do not throw an error if a table with the specified table name does not exist.
Supported Transitions
Not all data type transitions are supported. The limitations are listed below:
NOT NULLtoNULLABLEtransition is allowed for any non-PK column
ALTER TABLE IF EXISTS table ALTER COLUMN column SET DEFAULT
Keywords and parameters:
IF NOT EXISTS- do not throw an error if a table with the specified table name does not exist.
ALTER TABLE IF EXISTS table ALTER COLUMN column DROP DEFAULT
Keywords and parameters:
IF EXISTS- do not throw an error if a table with the specified table name does not exist.
ALTER TABLE IF EXISTS table SET EXPIRE AT
Keywords and parameters:
IF EXISTS- do not throw an error if a table with the specified table name does not exist.EXPIRE AT- allows specifying a column with a point in time when a record should be deleted.
ALTER TABLE IF EXISTS table DROP EXPIRE
Keywords and parameters:
IF EXISTS- do not throw an error if a table with the specified table name does not exist.DROP EXPIRE- disables row expiration for the table.
ALTER TABLE IF EXISTS table DROP SECONDARY ZONE
Removes the table from a secondary distribution zone.
Keywords and parameters:
IF EXISTS- do not throw an error if a table with the specified table name does not exist.DROP SECONDARY ZONE- removes the secondary zone for the table.
Examples:
ALTER TABLE IF EXISTS SET PARAMETER
Modifies the value of the specified parameter.
Keywords and parameters:
IF EXISTS- do not throw an error if a table with the specified table name does not exist.param_name- the name of a parameter to modify. The following parameters are supported:stale rows fraction- fraction of the table that must change for query execution plan to be recreated automatically. Default value is0.2.min stale rows- number of updates since the last query plan update required to automatically recreate query execution plan. Default value is500.
Examples:
ALTER TABLE IF EXISTS table SET ROW LEVEL SECURITY
Enables or disables row-level security on an existing table. When enabled, only rows permitted by the applicable policies are visible to a user. If no policy applies, the user sees no rows. For a conceptual overview, see Row-Level Security.
Keywords and parameters:
IF EXISTS- do not throw an error if a table with the specified table name does not exist.ON/OFF- whether to enable or disable row-level security on the table.
Examples:
DROP TABLE
The DROP TABLE command drops an existing table. The table will be marked for deletion and will be removed by garbage collection after the low watermark point is reached. Until the data is removed, it will be available to read-only transactions that check the time before the table was marked for deletion.
Keywords and parameters:
IF EXISTS- do not throw an error if a table with the same name does not exist.
Schema changes applied by this command are persisted on disk. Thus, the changes can survive full cluster restarts.
Examples:
Drop Person table if the one exists:
CREATE INDEX
Creates a new index.
When you create a new index, it will start building only after all transactions started before the index creation had been completed. Index build will not start if there are any “hung“ transactions in the logical topology of the cluster.
The index status, with the status reason description (e.g., PENDING - “Waiting for transaction ABC to complete”) is reflected in the system view.
Keywords and parameters:
IF NOT EXISTS- create the index only if an index with the same name does not exist.name- name of the index.ON- create index on the defined table.USING SORTED- if specified, creates a sorted index.USING HASH- if specified, creates a hash index.
Examples:
Create an index department_name_idx for the Person table:
Create a hash index department_name_idx for the Person table:
Create a sorted index department_city_idx for the Person table:
DROP INDEX
Drops an index.
When you drop an index, it stays in the STOPPING status until all transactions started before the DROP INDEX command had been completed (even those that do not affect any of the tables for which the index is being dropped). Upon completion of all transactions described above, the space the dropped index had occupied is freed up only when LWM of the relevant partition becomes greater than the time when the index dropping had been activated. The index status, with the status reason description (e.g., PENDING - “Waiting for transaction ABC to complete”) is reflected in the system view.
Keywords and parameters:
index_name- the name of the index.IF EXISTS- do not throw an error if an index with the specified name does not exist.
Examples:
Drop index if the one exists:
CREATE SCHEMA
Creates a new SQL schema.
Keywords and parameters:
IF NOT EXISTS- create the schema only if a cache with the same name does not exist.
The SYSTEM schema containing meta information is reserved for system use, for example for system views.
In conformance with SQL standard, INFORMATION_SCHEMA and DEFINITION_SCHEMA schema names are reserved, but are currently not used.
Additionally, GridGain uses the predefined PUBLIC schema as the default schema for simple name resolution.
DROP SCHEMA
Drops an existing SQL schema. Reserved schemas cannot be dropped.
Keywords and parameters:
IF EXISTS- do not throw an error if a schema with the specified name does not exist.RESTRICT- used by default. Schema will only be dropped if there are no objects in it.CASCADE- schema and all objects in it will be dropped.
CREATE CACHE
Creates a new cache.
Keywords and parameters:
IF NOT EXISTS- create the cache only if a cache with the same name does not exist.COLOCATE BY- colocation key. The key can be composite. Primary key must include colocation key. Wasaffinity_keyin GridGain 2.x.ZONE- sets the Distribution Zone. Can be specified as a case-sensitive string or case-insensitive identifier. Can be preceded byPRIMARYto signify the primary distribution zone.STORAGE PROFILE- sets the storage profile that will be used to store the table. Must be specified as a case-sensitive string. Can be preceded byPRIMARYto signify the primary storage profile.WRITE MODE- configures if the data is written to external store. Default value:SYNC. Possible values:SYNC- External Cache store writes are synchronous. KeyValueView operations won't return until external cache store write is complete.ASYNC- External Cache store writes are asynchronous and performed in background. KeyValueView operations may return before external cache store write completes.
EXPIRE AT- allows specifying a column with a point in time when a record should be deleted.expiry_column_name- name of the column that contains values on which the record expiry is based.
Example:
Creates a cache Accounts:
DROP CACHE
Drops an existing cache. The cache will be marked for deletion and will be removed by garbage collection after the low watermark point is reached.
Keywords and parameters:
IF EXISTS- do not throw an error if a cache with the same name does not exist.
Examples:
Drops Accounts cache if it exists:
ALTER CACHE
Modifies the settings of an existing cache.
ALTER CACHE IF EXISTS cache SET EXPIRE AT
Sets or updates the expiration column for a cache. Records will be automatically deleted when the timestamp in the specified column is reached.
Keywords and parameters:
IF EXISTS- do not throw an error if a cache with the specified name does not exist.expiry_column_name- the name of the column with expiration timestamps.
Examples:
Sets the expiration column for the Accounts cache:
ALTER CACHE IF EXISTS cache DROP EXPIRE
Removes the expiration configuration from a cache. Records will no longer be automatically deleted.
Keywords and parameters:
IF EXISTS- do not throw an error if a cache with the specified name does not exist.DROP EXPIRE- disables row expiration for the cache.
Examples:
Removes expiration from the Accounts cache:
CREATE SEQUENCE
Creates a new sequence object. You can use sequences to generate a sequence of numeric values in ascending or descending order. You can then use sequence functions to use them in your tables.
Keywords and parameters:
IF NOT EXISTS- create the sequence only if a sequence with the same name does not exist.INCREMENT BY- how much the sequence is incremented by each time. Can be both positive and negative. Default value: 1.If positive value is specified, the sequence is ascending.
If negative value is specified, the sequence is descending.
MINVALUE- the minimum value of the sequence. Default value: 1 for ascending sequences, minimum value supported by data type for descending sequences.MAXVALUE- the maximum value of the sequence.Default value: maximum value supported by data type for ascending sequences, -1 for descending sequences.START- the value the sequence starts at. Default value: same asMINVALUEfor ascending sequences, orMAXVALUEfor descending sequences.CACHE- the amount of sequence numbers that are pre-allocated and stored in memory. Default value: 1000. When preallocated values run out, next access to any sequence method will preallocate values again.ALTER SEQUENCEddl command and SETVAL() function reset the cache. Any numbers allocated but not used will be lost, resulting in “holes” in the sequence. All generated values are all distinct, not that they are generated purely sequentially.
Examples:
Creates a basic ascending sequence with default values:
Creates an ascending sequence that starts at 10, and increments by 10 up to the maximum value of 1000
Creates a descending sequence that starts at 15, and decrements by 50 up to the minimum value of -100;
Uses the defaultSequence sequence and the NEXTVAL() function to automatically increment the ID column in the table. When inserting values, you can skip the ID column and it will get incremented automatically:
ALTER SEQUENCE
Changes the properties of an existing sequence object.
Keywords and parameters:
IF NOT EXISTS- create the sequence only if a sequence with the same name does not exist.INCREMENT BY- how much the sequence is incremented by each time. Can be both positive and negative. Default value: 1.If positive value is specified, the sequence is ascending.
If negative value is specified, the sequence is descending.
MINVALUE- the minimum value of the sequence. Default value: 1 for ascending sequences, minimum value supported by data type for descending sequences.MAXVALUE- the maximum value of the sequence.Default value: maximum value supported by data type for ascending sequences, -1 for descending sequences.START- the value the sequence starts at. Default value: same asMINVALUEfor ascending sequences, orMAXVALUEfor descending sequences.CACHE- the amount of sequence numbers that are pre-allocated and stored in memory. Default value: 1000.
Examples:
Alters the default sequence to have 20000 as maximum value:
DROP SEQUENCE
Drops an existing sequence object.
This page is: Copyright © 2026 MariaDB. All rights reserved.
Last updated
Was this helpful?

