更新时间:2026-07-28 GMT+08:00
DDL
ROWID表的创建和删除(ASTORE+非段页式+非分区表为例):
gaussdb=# CREATE DATABASE ora dbcompatibility 'ORA';
CREATE DATABASE
gaussdb=# \c ora
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "ora" as user "$user".
--步骤1: 创建ROWID表
ora=# CREATE TABLE t1 (c1 INT) WITH (storage_type = ASTORE, segment = OFF, hasrowid = ON);
CREATE TABLE
--步骤2: 观察到创建的ROWNO序列、ROWNO索引对象
ora=# \d
List of relations
Schema | Name | Type | Owner | Storage
--------+--------+----------+-------+------------------------------------------------------------------------------
public | t1 | table | Mike | {orientation=row,storage_type=astore,segment=off,hasrowid=on,compression=no}
public | t1_seq | sequence | Mike |
(2 rows)
ora=# \di
List of relations
Schema | Name | Type | Owner | Table | Storage
--------+--------------+-------+-------+-------+---------
public | t1_rowno_idx | index | Mike | t1 |
(1 row)
--步骤3: 执行数据插入和ROWID查询
ora=# INSERT INTO t1 VALUES (1), (2), (3);
INSERT 0 3
ora=# SELECT rowid, rowno, * FROM t1;
rowid | rowno | c1
-------------------------------+-------+----
AAAAAAAAAP//AAAHvoAAAAAAAAAAB | 1 | 1
AAAAAAAAAP//AAAHvoAAAAAAAAAAC | 2 | 2
AAAAAAAAAP//AAAHvoAAAAAAAAAAD | 3 | 3
(3 rows)
ora=# SELECT rowid, rowno, * FROM t1 WHERE rowid = 'AAAAAAAAAP//AAAHvoAAAAAAAAAAC';
rowid | rowno | c1
-------------------------------+-------+----
AAAAAAAAAP//AAAHvoAAAAAAAAAAC | 2 | 2
(1 row)
--步骤4: 删除ROWID表
ora=# DROP TABLE t1;
DROP TABLE
--步骤5: 观察到ROWNO序列、ROWNO索引对象已被级联删除
ora=# \d
No relations found.
ora=# \di
No relations found.
ora=# \c postgres
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "postgres" as user "$user".
gaussdb=# DROP DATABASE ora;
DROP DATABASE 非ROWID表转换为ROWID表(ASTORE+非段页式+非分区表为例):
gaussdb=# CREATE DATABASE ora dbcompatibility 'ORA';
CREATE DATABASE
gaussdb=# \c ora
--步骤1: 创建非ROWID表
ora=# CREATE TABLE t1 (c1 INT) WITH (storage_type = ASTORE, segment = OFF);
CREATE TABLE
--步骤2: 观察到只有表对象
ora=# \d
List of relations
Schema | Name | Type | Owner | Storage
--------+------+-------+-------+------------------------------------------------------------------
public | t1 | table | Mike | {orientation=row,storage_type=astore,segment=off,compression=no}
(1 row)
ora=# \di
No relations found.
--步骤3: 将非ROWID表转换为ROWID表
ora=# ALTER TABLE t1 SET WITH ROWID;
ALTER TABLE
--步骤4: 观察到创建的ROWNO序列、ROWNO索引对象
ora=# \d
List of relations
Schema | Name | Type | Owner | Storage
--------+--------+----------+-------+------------------------------------------------------------------------------
public | t1 | table | Mike | {orientation=row,storage_type=astore,segment=off,compression=no,hasrowid=on}
public | t1_seq | sequence | Mike |
(2 rows)
ora=# \di
List of relations
Schema | Name | Type | Owner | Table | Storage
--------+--------------+-------+-------+-------+---------
public | t1_rowno_idx | index | Mike | t1 |
(1 row)
ora=# \c postgres
Non-SSL connection (SSL connection is recommended when requiring high-security)
You are now connected to database "postgres" as user "$user".
gaussdb=# DROP DATABASE ora;
DROP DATABASE DDL语法的详细介绍请参见《参考》中“SQL参考 > SQL语法”章节
父主题: 使用指导