Purpose
You can use this statement to modify the structure of an existing table. For example, you can modify a table and its attributes, add columns, modify columns and their attributes, and drop columns.
Syntax
alter_table_stmt:
ALTER TABLE table_name alter_table_action_list;
alter_table_action_list:
alter_table_action [, alter_table_action ...]
alter_table_action:
ADD {column_definition | (column_definition_list)}
| ADD [CONSTRAINT [constraint_name]] UNIQUE (column_name [, column_name ]...)
| ADD [CONSTRAINT [constraint_name]] FOREIGN KEY (column_name_list) references_clause
| ADD [CONSTRAINT [constraint_name]] CHECK (expr)
| ADD CONSTRAINT constraint_name PRIMARY KEY (column_name)
| ADD CONSTRAINT constraint_name FOREIGN KEY(foreign_col_name) REFERENCES
reference_tbl_name(column_name);
| ALTER INDEX index_name [VISIBLE | INVISIBLE]
| ADD range_partition_list
| ADD COLUMN GROUP([all columns, ]each column)
| DROP {PARTITION | SUBPARTITION} partition_name_list [UPDATE GLOBAL INDEXES]
| DROP TABLEGROUP
| DROP CONSTRAINT constraint_name
| DROP PRIMARY KEY
| DROP COLUMN column_name
| DROP COLUMN GROUP([all columns, ]each column)
| {ENABLE | DISABLE} CONSTRAINT constraint_name
| MODIFY [COLUMN] column_definition
| MODIFY CONSTRAINT constraint_name { ENABLE | DISABLE }
| MODIFY PRIMARY KEY (column_name_list)
| RENAME [TO] table_name
| RENAME COLUMN old_col_name TO new_col_name
| RENAME { PARTITION | SUBPARITION } partition_name TO new_name
| SET TABLEGROUP tablegroup_name
| [SET] table_option_list
| TRUNCATE {PARTITION | SUBPARTITION} partition_name_list [UPDATE GLOBAL INDEXES]
rename_table_action_list:
rename_table_action [, rename_table_action ...]
rename_table_action:
table_name TO table_name
column_definition_list:
column_definition [, column_definition ...]
column_definition:
column_name data_type
[DEFAULT const_value] [AUTO_INCREMENT]
[NULL | NOT NULL] [[PRIMARY] KEY] [UNIQUE [KEY]] [COMMENT string_value] [SKIP_INDEX(skip_index_option_list)]
skip_index_option_list:
skip_index_option [,skip_index_option ...]
skip_index_option:
MIN_MAX
| SUM
column_desc_list:
column_desc [, column_desc ...]
column_desc:
column_name [(length)] [ASC | DESC]
references_clause:
REFERENCES table_name [ (column_name, column_name ...) ] [ON DELETE {SET NULL | CASCADE}]
index_option:
[GLOBAL | LOCAL]
| block_size
| compression
| STORING(column_name_list)
| COMMENT string_value
table_option_list:
table_option [ table_option ...]
table_option:
table_group
| block_size
| compression
| AUTO_INCREMENT [=] INT_VALUE
| COMMENT string_value
| parallel_clause
parallel_clause:
{NOPARALLEL | PARALLEL integer}
partition_option:
PARTITION BY HASH(column_name_list)
[subpartition_option] hash_partition_define
| PARTITION BY RANGE (column_name_list)
[subpartition_option] (range_partition_list)
| PARTITION BY LIST (column_name_list)
[subpartition_option] (list_partition_list)
/*Template-based subpartition*/
subpartition_option:
SUBPARTITION BY HASH (column_name_list) hash_subpartition_define
| SUBPARTITION BY RANGE (column_name_list) SUBPARTITION TEMPLATE
(range_subpartition_list)
| SUBPARTITION BY LIST (column_name_list) SUBPARTITION TEMPLATE
(list_subpartition_list)
/*Non-template-based subpartition*/
subpartition_option:
SUBPARTITION BY HASH (column_name_list)
| SUBPARTITION BY RANGE (column_name_list)
| SUBPARTITION BY LIST (column_name_list)
subpartition_list:
(hash_subpartition_list)
| (range_subpartition_list)
| (list_subpartition_list)
hash_partition_define:
PARTITIONS partition_count [TABLESPACE tablespace] [compression]
| (hash_partition_list)
hash_partition_list:
hash_partition [, hash_partition, ...]
hash_partition:
partition [partition_name] [subpartition_list/*Only non-template-based subpartitions can be defined.*/]
hash_subpartition_define:
SUBPARTITIONS subpartition_count
| SUBPARTITION TEMPLATE (hash_subpartition_list)
hash_subpartition_list:
hash_subpartition [, hash_subpartition, ...]
hash_subpartition:
subpartition [subpartition_name]
range_partition_list:
range_partition [, range_partition ...]
range_partition:
PARTITION [partition_name]
VALUES LESS THAN {(expression_list) | (MAXVALUE)}
[subpartition_list/*Only non-template-based subpartitions can be defined.*/]
[ID = num] [physical_attribute_list] [compression]
range_subpartition_list:
range_subpartition [, range_subpartition ...]
range_subpartition:
SUBPARTITION subpartition_name
VALUES LESS THAN {(expression_list) | MAXVALUE} [physical_attribute_list]
list_partition_list:
list_partition [, list_partition] ...
list_partition:
PARTITION [partition_name]
VALUES (DEFAULT|expression_list)
[subpartition_list/*Only non-template-based subpartitions can be defined.*/]
[ID num] [physical_attribute_list] [compression]
list_subpartition_list:
list_subpartition [, list_subpartition] ...
list_subpartition:
SUBPARTITION [partition_name] VALUES (DEFAULT|expression_list) [physical_attribute_list]
expression_list:
expression [, expression ...]
column_name_list:
column_name [, column_name ...]
partition_name_list:
partition_name [, partition_name ...]
partition_count | subpartition_count:
INT_VALUE
Parameters
| Parameter | Description |
|---|---|
| ADD | Adds a column. You cannot add a primary key column. |
| MODIFY COLUMN | Modifies the column attribute. |
| MODIFY CONSTRAINT | Enables or disables the FOREIGN KEY constraint or CHECK constraint. |
| DROP PRIMARY KEY | Drops a primary key. Note: In Oracle mode, you cannot drop the primary key of a table that is the parent table referenced by a foreign key. |
| DROP COLUMN | Drops a column. You cannot drop a primary key column or columns that contain indexes. |
| ADD UNIQUE | Adds a unique index. |
| ADD INDEX | Adds a normal index. |
| ALTER INDEX | Modifies index attributes. |
| FOREIGN KEY | Adds a foreign key. If you do not specify the name of the foreign key, it will be named in the format of table name + OBFK + time when the foreign key was created. For example, the foreign key created for table t1 at 00:00:00 on August 1, 2021 is named as t1_OBFK_1627747200000000. A foreign key enables one table (child table) to reference data from another table (parent table). |
| ADD PARTITION | Adds a partition. |
| DROP {PARTITION | SUBPARTITION} | Drops a partition. Valid values:
UPDATE GLOBAL INDEXES, the system updates global indexes when dropping the partitions or subpartitions. If you do not specify UPDATE GLOBAL INDEXES, the global indexes on the partitioned or subpartitioned table must be in an unusable state. Separate multiple partition names with commas (,). Notice: Before dropping a partition, ensure that there are no active transactions or queries in this partition. Otherwise, SQL statement errors or exceptions may occur. |
| TRUNCATE {PARTITION | SUBPARTITION} | Truncates a partition. Valid values:
UPDATE GLOBAL INDEXES, the system updates global indexes when deleting the data. If you do not specify UPDATE GLOBAL INDEXES, the global indexes on the partitioned or subpartitioned table must be in an unusable state. Separate multiple partition names with commas (,). Notice: Before truncating a partition, ensure that there are no active transactions or queries in this partition. Otherwise, SQL statement errors or exceptions may occur. |
| RENAME [TO] table_name | Renames a table. |
| RENAME { PARTITION | SUBPARITION } partition_name TO new_name | Renames a partition or subpartition. new_name indicates the new name, which is case insensitive. Renaming affects the partitions or subpartitions of the primary table but does not affect those of local indexes. You can query the USER_TAB_PARTITIONS and USER_TAB_SUBPARTITIONS views to check the renaming result. For more information, see Rename a partition. If you attempt to rename a partition or subpartition locked for a DML operation, the rename operation is blocked. The partition or subpartition can be renamed only after the DML operation releases the lock. |
| DROP TABLEGROUP | Drops a table group. |
| SET TABLEGROUP | Sets the table group to which the table belongs. |
| DROP CONSTRAINT | Drops a constraint. |
| SET BLOCK_SIZE | Sets the block size of a table partition. |
| SET COMPRESSION | Sets the compression mode of the table. |
| SET USE_BLOOM_FILTER | Specifies whether to use BloomFilter. |
| SET COMMENT | Sets comment information. |
| SET PROGRESSIVE_MERGE_NUM | Sets the number of progressive compaction steps. Value range: [0,100]. |
| parallel_clause | The degree of parallelism (DOP) at the table level.
ALTER SESSION statement > DOP at the table level. |
| {ENABLE | DISABLE} CONSTRAINT constraint_name | Enables or disables the FOREIGN KEY constraint or CHECK constraint. |
| MODIFY PRIMARY KEY | Modifies a primary key. |
| ADD COLUMN GROUP([all columns,]each column) | Converts a table into a columnstore table. The following options are supported:
|
| DROP COLUMN GROUP([all columns,]each column) | Removes the storage format of the table. The following options are supported:
|
| SKIP_INDEX | Modifies the skip index attribute of a column. Valid values:
Notice
|
Examples
Modify the data type of
col1in thetbl1table.obclient> CREATE TABLE tbl1(col1 VARCHAR(3)); Query OK, 0 rows affected obclient> ALTER TABLE tbl1 MODIFY col1 CHAR(10); Query OK, 0 rows affected obclient> DESCRIBE tbl1; +-------+----------+------+-----+---------+-------+ | FIELD | TYPE | NULL | KEY | DEFAULT | EXTRA | +-------+----------+------+-----+---------+-------+ | COL1 | CHAR(10) | YES | NULL | NULL | NULL | +-------+----------+------+-----+---------+-------+ 1 row in setChange the name of the
col1column in thetbl1table tocol2.obclient> ALTER TABLE tbl1 RENAME COLUMN col1 TO col2; Query OK, 0 rows affected obclient> DESCRIBE tbl1; +-------+-------------+------+-----+---------+-------+ | FIELD | TYPE | NULL | KEY | DEFAULT | EXTRA | +-------+-------------+------+-----+---------+-------+ | COL2 | VARCHAR2(10) | YES | NULL | NULL | NULL| +-------+-------------+------+-----+---------+-------+ 1 row in setAdd and drop a column.
Create a table named
tbl2.obclient> CREATE TABLE tbl2 (col1 NUMBER(30) PRIMARY KEY,col2 VARCHAR(50)); Query OK, 0 rows affectedAdd the
col3column to thetbl2table.obclient> ALTER TABLE tbl2 ADD col3 NUMBER(30); Query OK, 0 rows affected obclient> DESCRIBE tbl2; +-------+--------------+------+-----+---------+-------+ | FIELD | TYPE | NULL | KEY | DEFAULT | EXTRA | +-------+--------------+------+-----+---------+-------+ | COL1 | NUMBER(30) | NO | PRI | NULL | NULL | | COL2 | VARCHAR2(50) | YES | NULL| NULL | NULL | | COL3 | NUMBER(30) | YES | NULL| NULL | NULL | +-------+--------------+------+-----+---------+-------+ 3 rows in setDrop the
col3column from thetbl2table.obclient> ALTER TABLE tbl2 DROP COLUMN col3; Query OK, 0 rows affected obclient> DESCRIBE tbl2; +-------+--------------+------+-----+---------+-------+ | FIELD | TYPE | NULL | KEY | DEFAULT | EXTRA | +-------+--------------+------+-----+---------+-------+ | COL1 | NUMBER(30) | NO | PRI | NULL | NULL | | COL2 | VARCHAR2(50) | YES | NULL| NULL | NULL | +-------+--------------+------+-----+---------+-------+ 2 rows in setCreate a unique index for the table
tbl2.obclient> CREATE TABLE tbl2 (col1 NUMBER(30) PRIMARY KEY,col2 VARCHAR(50), col3 INT); Query OK, 0 rows affected obclient> ALTER TABLE tbl2 ADD CONSTRAINT constraint_TBL2 UNIQUE (col2, col3); Query OK, 0 rows affected obclient [SYS]> DESC tbl2; +-------+--------------+------+-----+---------+-------+ | FIELD | TYPE | NULL | KEY | DEFAULT | EXTRA | +-------+--------------+------+-----+---------+-------+ | COL1 | NUMBER(30) | NO | PRI | NULL | NULL | | COL2 | VARCHAR2(50) | YES | MUL | NULL | NULL | | COL3 | NUMBER(38) | YES | NULL| NULL | NULL | +-------+--------------+------+-----+---------+-------+ 3 rows in set obclient> INSERT INTO tbl2 VALUES('1','2','2'); Query OK, 1 row affected obclient> INSERT INTO tbl2 VALUES('2','2','2'); ORA-00001: unique constraint '2-2' for key 'CONSTRAINT_TBL2' violated obclient> INSERT INTO tbl2 VALUES('2','3','2'); Query OK, 1 row affected
Specify a foreign key for the
ref_t2table. Specify to execute theSET NULLaction when aDELETEoperation affects a key value in the parent table that has matching rows in the child table.obclient> CREATE TABLE ref_t1(c1 INT PRIMARY KEY,C2 INT); Query OK, 0 rows affected obclient> CREATE TABLE ref_t2(c1 INT PRIMARY KEY,C2 INT); Query OK, 0 rows affected obclient> ALTER TABLE ref_t2 ADD CONSTRAINT fk1 FOREIGN KEY (c2) REFERENCES ref_t1(c1) ON DELETE SET NULL; Query OK, 0 row affectedAdd the
p1_r4subpartition to thep1partition in a non-template-based subpartitioned table namedtbl3.obclient> ALTER TABLE tbl3 MODIFY PARTITION p1 ADD SUBPARTITION p1_r4 VALUES LESS THAN(2022); Query OK, 0 rows affectedDrop the
p2_r3subpartition from a non-template-based subpartitioned table namedtbl3.obclient> ALTER TABLE tbl3 DROP SUBPARTITION p2_r3; Query OK, 0 rows affectedAdd the
p4partition to a non-template-based subpartitioned table namedtbl3. You need to specify both the partition definition and the subpartition definition.obclient> ALTER TABLE tbl3 ADD PARTITION p4 VALUES LESS THAN (400) ( SUBPARTITION p4_r1 VALUES LESS THAN (2019), SUBPARTITION p4_r2 VALUES LESS THAN (2020), SUBPARTITION p4_r3 VALUES LESS THAN (2021) ); Query OK, 0 rows affectedAdd the
p3partition to a template-based subpartitioned table namedtbl4. You need to specify only the partition definition. The subpartition definition is filled in automatically based on the template.obclient> CREATE TABLE tbl4(col1 INT, col2 INT, PRIMARY KEY(col1,col2)) PARTITION BY RANGE(col1) SUBPARTITION BY RANGE(col2) SUBPARTITION TEMPLATE ( SUBPARTITION p0 VALUES LESS THAN (50), SUBPARTITION p1 VALUES LESS THAN (100) ) ( PARTITION p0 VALUES LESS THAN (100), PARTITION p1 VALUES LESS THAN (200), PARTITION p2 VALUES LESS THAN (300) ); Query OK, 0 rows affected obclient> ALTER TABLE tbl4 ADD PARTITION p3 VALUES LESS THAN (400); Query OK, 0 rows affectedChange the DOP of the
tbl5table to3.obclient> CREATE TABLE tbl5(col1 INT PRIMARY KEY, col2 INT) PARALLEL 5; Query OK, 0 rows affected obclient> ALTER TABLE tbl5 PARALLEL 3; Query OK, 0 rows affectedModify the status of a
FOREIGN KEYconstraint.obclient> CREATE TABLE MMS_GROUPUSER ( "ID" VARCHAR2(254 BYTE) NOT NULL, "GROUPID" VARCHAR2(254 BYTE), "USERID" VARCHAR2(254 BYTE), CONSTRAINT "PK_MMS_GROUPUSER" PRIMARY KEY ("ID"), CONSTRAINT "FK_MMS_GROUPUSER_02" FOREIGN KEY ("GROUPID") REFERENCES MMS_GROUPUSER ("ID") ON DELETE CASCADE DISABLE ); Query OK, 0 rows affected obclient> SELECT constraint_name,constraint_type,table_name,status FROM user_constraints WHERE constraint_name LIKE 'FK_MMS_GROUPUSE%'; +---------------------+-----------------+---------------+----------+ | CONSTRAINT_NAME | CONSTRAINT_TYPE | TABLE_NAME | STATUS | +---------------------+-----------------+---------------+----------+ | FK_MMS_GROUPUSER_02 | R | MMS_GROUPUSER | DISABLED | +---------------------+-----------------+---------------+----------+ 1 row in set obclient> ALTER TABLE MMS_GROUPUSER ENABLE CONSTRAINT FK_MMS_GROUPUSER_02; Query OK, 0 rows affected obclient> SELECT constraint_name,constraint_type,table_name,status FROM user_constraints WHERE constraint_name LIKE 'FK_MMS_GROUPUSE%'; +---------------------+-----------------+---------------+---------+ | CONSTRAINT_NAME | CONSTRAINT_TYPE | TABLE_NAME | STATUS | +---------------------+-----------------+---------------+---------+ | FK_MMS_GROUPUSER_02 | R | MMS_GROUPUSER | ENABLED | +---------------------+-----------------+---------------+---------+ 1 row in setTruncate the
M202001andM202002partitions of thetbl6partitioned table.obclient> CREATE TABLE tbl6 (log_id number NOT NULL,log_value varchar2(50),log_date date NOT NULL DEFAULT sysdate) PARTITION BY RANGE(log_date) ( PARTITION M202001 VALUES LESS THAN(TO_DATE('2020/02/01','YYYY/MM/DD')) , PARTITION M202002 VALUES LESS THAN(TO_DATE('2020/03/01','YYYY/MM/DD')) , PARTITION M202003 VALUES LESS THAN(TO_DATE('2020/04/01','YYYY/MM/DD')) , PARTITION M202004 VALUES LESS THAN(TO_DATE('2020/05/01','YYYY/MM/DD')) , PARTITION M202005 VALUES LESS THAN(TO_DATE('2020/06/01','YYYY/MM/DD')) , PARTITION MMAX VALUES LESS THAN (MAXVALUE) ); Query OK, 0 rows affected obclient> ALTER TABLE tbl6 TRUNCATE PARTITION M202001, M202002 UPDATE GLOBAL INDEXES; Query OK, 0 rows affectedDrop the
CHECKconstraint namedtbl7_equal_check1on thetbl7table.obclient> CREATE TABLE tbl7 (col1 INT, col2 INT, col3 INT,CONSTRAINT tbl7_equal_check1 CHECK(col2 = col3 * 2) ENABLE VALIDATE); Query OK, 0 rows affected obclient> SELECT constraint_name,constraint_type,table_name,status FROM user_constraints WHERE table_name LIKE 'TBL%'; +-------------------+-----------------+------------+---------+ | CONSTRAINT_NAME | CONSTRAINT_TYPE | TABLE_NAME | STATUS | +-------------------+-----------------+------------+---------+ | TBL8_EQUAL_CHECK1 | C | TBL8 | ENABLED | | TBL7_EQUAL_CHECK1 | C | TBL7 | ENABLED | +-------------------+-----------------+------------+---------+ 2 rows in set obclient> ALTER TABLE tbl7 DROP CONSTRAINT tbl7_equal_check1; Query OK, 0 rows affected obclient> SELECT constraint_name,constraint_type,table_name,status FROM user_constraints WHERE table_name LIKE 'TBL%'; +-------------------+-----------------+------------+---------+ | CONSTRAINT_NAME | CONSTRAINT_TYPE | TABLE_NAME | STATUS | +-------------------+-----------------+------------+---------+ | TBL8_EQUAL_CHECK1 | C | TBL8 | ENABLED | +-------------------+-----------------+------------+---------+ 1 row in setMove the
tbl8table from thetblgroup1table group to thetblgroup2table group.obclient> SHOW TABLEGROUPS; +-----------------+------------+---------------+ | TABLEGROUP_NAME | TABLE_NAME | DATABASE_NAME | +-----------------+------------+---------------+ | TBLGROUP1 | TBL8 | SYS | | TBLGROUP2 | NULL | NULL | | oceanbase | NULL | NULL | +-----------------+------------+---------------+ 3 rows in set obclient> ALTER TABLE tbl8 SET TABLEGROUP tblgroup2; Query OK, 0 rows affected obclient> SHOW TABLEGROUPS; +-----------------+------------+---------------+ | TABLEGROUP_NAME | TABLE_NAME | DATABASE_NAME | +-----------------+------------+---------------+ | TBLGROUP1 | NULL | NULL | | TBLGROUP2 | TBL8 | SYS | | oceanbase | NULL | NULL | +-----------------+------------+---------------+ 3 rows in setAdd a
FOREIGN KEYconstraint namedcons_fk1to theprimary_tabletable.obclient> CREATE TABLE primary_table (id NUMBER PRIMARY KEY, names VARCHAR(100) NOT NULL, foreign_col NUMBER); Query OK, 0 rows affected obclient> CREATE TABLE reference_table (id NUMBER PRIMARY key, comments VARCHAR2(100) NOT NULL); Query OK, 0 rows affected obclient> ALTER TABLE primary_table ADD CONSTRAINT cons_fk1 FOREIGN KEY(foreign_col) REFERENCES reference_table(id); Query OK, 0 rows affectedAdd a
PRIMARY KEYconstraint namedtbl1_pkto thetbl9table.obclient> CREATE TABLE tbl9 (col1 NUMBER, col2 INT,col3 VARCHAR2(100)); Query OK, 0 rows affected obclient> ALTER TABLE tbl9 ADD CONSTRAINT tbl1_pk PRIMARY KEY (col1); Query OK, 0 rows affectedChange the primary key of the
tbl9table to thecol2column.obclient> ALTER TABLE tbl9 MODIFY PRIMARY KEY(col2); Query OK, 0 rows affectedDrop the primary key of the
tbl9table.obclient> ALTER TABLE tbl9 DROP PRIMARY KEY; Query OK, 0 rows affectedRename a partition and a subpartition.
/* Create a subpartitioned table named range_range_table and create a local index based on col1. */ CREATE TABLE range_range_table(col1 INT, col2 INT, col3 INT) PARTITION BY RANGE(col1) SUBPARTITION BY RANGE(col2) (PARTITION p0 VALUES LESS THAN(100) (SUBPARTITION sp0 VALUES LESS THAN(100), SUBPARTITION sp1 VALUES LESS THAN(200) ), PARTITION p1 VALUES LESS THAN(200) (SUBPARTITION sp2 VALUES LESS THAN(100), SUBPARTITION sp3 VALUES LESS THAN(200), SUBPARTITION sp4 VALUES LESS THAN(300) ) ); CREATE INDEX local_idx_for_range_range_tb ON range_range_table (col1) LOCAL; /* Rename a partition. The partition name in the local index remains unchanged. */ obclient> SELECT partition_name FROM sys.user_tab_partitions WHERE table_name = 'RANGE_RANGE_TABLE'; +----------------+ | PARTITION_NAME | +----------------+ | P0 | | P1 | +----------------+ 2 rows in set obclient> ALTER TABLE range_range_table RENAME PARTITION p0 TO p10; Query OK, 0 rows affected obclient> SELECT partition_name FROM sys.user_tab_partitions WHERE table_name = 'RANGE_RANGE_TABLE'; +----------------+ | PARTITION_NAME | +----------------+ | P10 | | P1 | +----------------+ 2 rows in set obclient> SELECT partition_name FROM sys.user_ind_partitions WHERE index_name = 'LOCAL_IDX_FOR_RANGE_RANGE_TB'; +----------------+ | PARTITION_NAME | +----------------+ | P0 | | P1 | +----------------+ 2 rows in set /* Rename a subpartition. The subpartition name in the local index remains unchanged. */ obclient> SELECT partition_name, subpartition_name FROM sys.user_tab_subpartitions WHERE table_name = 'RANGE_RANGE_TABLE'; +----------------+-------------------+ | PARTITION_NAME | SUBPARTITION_NAME | +----------------+-------------------+ | P10 | SP0 | | P10 | SP1 | | P1 | SP2 | | P1 | SP3 | | P1 | SP4 | +----------------+-------------------+ 5 rows in set obclient> ALTER TABLE range_range_table RENAME SUBPARTITION sp0 TO sp10; Query OK, 0 rows affected obclient> SELECT partition_name, subpartition_name FROM sys.user_tab_subpartitions WHERE table_name = 'RANGE_RANGE_TABLE'; +----------------+-------------------+ | PARTITION_NAME | SUBPARTITION_NAME | +----------------+-------------------+ | P10 | SP10 | | P10 | SP1 | | P1 | SP2 | | P1 | SP3 | | P1 | SP4 | +----------------+-------------------+ 5 rows in set obclient> SELECT partition_name, subpartition_name FROM sys.user_ind_subpartitions WHERE index_name = 'LOCAL_IDX_FOR_RANGE_RANGE_TB'; +----------------+-------------------+ | PARTITION_NAME | SUBPARTITION_NAME | +----------------+-------------------+ | P0 | SP0 | | P0 | SP1 | | P1 | SP2 | | P1 | SP3 | | P1 | SP4 | +----------------+-------------------+ 5 rows in setModify the columnstore attribute of a table.
Create a table named
tbl1.CREATE TABLE tbl1 (col1 INT PRIMARY KEY, col2 VARCHAR(50));Convert the
tbl1table into a rowstore-columnstore redundant table, and then drop the rowstore-columnstore redundancy attribute.ALTER TABLE tbl1 ADD COLUMN GROUP(all columns, each column);ALTER TABLE tbl1 DROP COLUMN GROUP(all columns, each column);Convert the
tbl1table into a columnstore table, and then drop the columnstore attribute.ALTER TABLE tbl1 ADD COLUMN GROUP(each column);ALTER TABLE tbl1 DROP COLUMN GROUP(each column);
Modify the skip index attribute of a column in the table.
Use the following SQL statement to create a table named
test_skidx.CREATE TABLE test_skidx( col1 NUMBER SKIP_INDEX(MIN_MAX, SUM), col2 FLOAT SKIP_INDEX(MIN_MAX), col3 VARCHAR2(1024) SKIP_INDEX(MIN_MAX), col4 CHAR(10) );Change the type of the skip index on the
col2column in thetest_skidxtable toSUM.ALTER TABLE test_skidx MODIFY col2 FLOAT SKIP_INDEX(SUM);Add the skip index attribute for a column after the table is created.
Add a skip index of the
MIN_MAXtype for thecol4column in thetest_skidxtable.ALTER TABLE test_skidx MODIFY col4 CHAR(10) SKIP_INDEX(MIN_MAX);Delete the skip index attribute for a column after the table is created.
Delete the skip index attribute of the
col1column in thetest_skidxtable.ALTER TABLE test_skidx MODIFY col1 NUMBER SKIP_INDEX();