postgresql建表带注释_使用PostgreSQL为表或视图创建备注的操作

本文介绍了如何在PostgreSQL中为表、列、约束以及视图添加注释,包括创建表、视图的示例及对应的COMMENT ON语句。同时,提供了查询表和视图注释的SQL查询示例。
摘要由CSDN通过智能技术生成

1 为表和列创建备注

drop table if exists test;

create table test(

objectid serial not null,

num integer not null,

constraint pk_test_objectid primary key (objectid),

constraint ck_test_num check(num < 123 ),

);

comment on table test is '我是表';

comment on column test.objectid is '我是唯一主键';

comment on column test.num is '数量字段';

comment on constraint pk_test_objectid on test is '我是约束,唯一主键';

comment on constraint ck_test_num on test is '我是约束,num字段必须小于123';

\dS+ test;

2 为视图和列创建备注

drop view if exists vtest;

create or replace view vtest

as select 1 as col1, 'a' as col2, now() as col3;

comment on view vtest is '视图备注';

comment on column vtest.col1 is '第一列备注,integer类型';

comment on column vtest.col2 is '第二列备注,字符类型';

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值