加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

postgresql表和列注释(描述)

发布时间:2020-12-13 16:45:00 所属栏目:百科 来源:网络整理
导读:PostgreSQL添加表和列注释。本文为测试表test,默认无注释。 test=# d+ 关联列表 架构模式 | 名称 | 类型 | 拥有者 | 大小 | 描述----------+------+--------+----------+---------+------ public | test | 数据表 | postgres | 0 bytes |(1 行记录)test=#

PostgreSQL添加表和列注释。本文为测试表test,默认无注释。

test=# d+
                       关联列表
 架构模式 | 名称 |  类型  |  拥有者  |  大小   | 描述
----------+------+--------+----------+---------+------
 public   | test | 数据表 | postgres | 0 bytes |
(1 行记录)

test=# comment on table test is '测试表';
COMMENT
test=# d+
                        关联列表
 架构模式 | 名称 |  类型  |  拥有者  |  大小   |  描述
----------+------+--------+----------+---------+--------
 public   | test | 数据表 | postgres | 0 bytes | 测试表
(1 行记录)

test=#

下面演示添加列注释。

test=# alter table test add column id int primary key;
ALTER TABLE
test=# alter table test add column name text not null;
ALTER TABLE
test=# alter table test add column sex boolean default true;
ALTER TABLE
test=# comment on column test.id is 'ID表';
COMMENT
test=# d+
                         关联列表
 架构模式 | 名称 |  类型  |  拥有者  |    大小    |  描述
----------+------+--------+----------+------------+--------
 public   | test | 数据表 | postgres | 8192 bytes | 测试表
(1 行记录)

test=# d+ test
                             数据表 "public.test"
 栏位 |  类型   | Collation | Nullable | Default |   存储   | 统计目标 | 描述
------+---------+-----------+----------+---------+----------+----------+------
 id   | integer |           | not null |         | plain    |          | ID表
 name | text    |           | not null |         | extended |          |
 sex  | boolean |           |          | true    | plain    |          |
索引:
    "test_pkey" PRIMARY KEY,btree (id)

test=#

删除表和列注释只需要将注释信息设置为空即可。也可以使用IS NULL命令。

test=# comment on column test.id is '';
COMMENT
test=# comment on table test is '';
COMMENT
test=# d
              关联列表
 架构模式 | 名称 |  类型  |  拥有者
----------+------+--------+----------
 public   | test | 数据表 | postgres
(1 行记录)

test=# d+
                        关联列表
 架构模式 | 名称 |  类型  |  拥有者  |    大小    | 描述
----------+------+--------+----------+------------+------
 public   | test | 数据表 | postgres | 8192 bytes |
(1 行记录)

test=# d+ test
                             数据表 "public.test"
 栏位 |  类型   | Collation | Nullable | Default |   存储   | 统计目标 | 描述
------+---------+-----------+----------+---------+----------+----------+------
 id   | integer |           | not null |         | plain    |          |
 name | text    |           | not null |         | extended |          |
 sex  | boolean |           |          | true    | plain    |          |
索引:
    "test_pkey" PRIMARY KEY,btree (id)

test=#
#IS NULL 练习
test=# comment on column test.id is 'ID信息';
COMMENT
test=# comment on table test is '测试信息';
COMMENT
test=# d+
                          关联列表
 架构模式 | 名称 |  类型  |  拥有者  |    大小    |   描述
----------+------+--------+----------+------------+----------
 public   | test | 数据表 | postgres | 8192 bytes | 测试信息
(1 行记录)

test=# d+ test
                              数据表 "public.test"
 栏位 |  类型   | Collation | Nullable | Default |   存储   | 统计目标 |  描述
------+---------+-----------+----------+---------+----------+----------+--------
 id   | integer |           | not null |         | plain    |          | ID信息
 name | text    |           | not null |         | extended |          |
 sex  | boolean |           |          | true    | plain    |          |
索引:
    "test_pkey" PRIMARY KEY,btree (id)

test=# comment on column test.id is null;
COMMENT
test=# comment on table test is null;
COMMENT
test=#

参考链接

http://www.postgres.cn/docs/9.6/sql-comment.html

https://www.postgresql.org/docs/current/static/sql-comment.html

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读