云数据库 GAUSSDB-COMMENT:示例

时间:2024-11-13 14:46:30

示例

--建表。
gaussdb=# CREATE TABLE emp(
    empno varchar(7),
    ename varchar(50),
    job varchar(50),
    mgr varchar(7),
    deptno int
);

--表添加注释。
gaussdb=# COMMENT ON TABLE emp IS '部门表';

--字段添加注释。
gaussdb=# COMMENT ON COLUMN emp.empno  IS  '员工编号';
gaussdb=# COMMENT ON COLUMN emp.ename  IS  '员工姓名';
gaussdb=# COMMENT ON COLUMN emp.job    IS  '职务';
gaussdb=# COMMENT ON COLUMN emp.mgr    IS  '上司编号';
gaussdb=# COMMENT ON COLUMN emp.deptno IS  '部门编号';

--查看表的注释。
gaussdb=# \d+
 Schema |    Name     |   Type   | Owner |    Size    |             Storage              | Description 
--------+-------------+----------+-------+------------+----------------------------------+-------------
 public | emp         | table    | omm   | 0 bytes    | {orientation=row,compression=no} | 部门表

--查看字段注释。
gaussdb=# \d+ emp
                                 Table "public.emp"
 Column |         Type          | Modifiers | Storage  | Stats target | Description 
--------+-----------------------+-----------+----------+--------------+-------------
 empno  | character varying(7)  |           | extended |              | 员工编号
 ename  | character varying(50) |           | extended |              | 员工姓名
 job    | character varying(50) |           | extended |              | 职务
 mgr    | character varying(7)  |           | extended |              | 上司编号
 deptno | integer               |           | plain    |              | 部门编号
Has OIDs: no
Distribute By: HASH(empno)
Location Nodes: ALL DATANODES
Options: orientation=row, compression=no

--删除表emp。
gaussdb=# DROP TABLE emp;
support.huaweicloud.com/distributed-devg-v8-gaussdb/gaussdb-12-0528.html