1.添加注释
--语法
comment on [type] [target] is [comment]
--为表添加注释
comment on table user is 'The user table';
--为字段注释
comment on column user.userid is 'The user ID';
2.查询注释
--查询字段注释,objsubid为表中字段的序号,从左侧从1开始
select description from pg_description
join pg_class on pg_description.objoid = pg_class.oid
where relname = 'tablename'
--查询表名、表注释
select relname as tabname,
cast(obj_description(relfilenode,'pg_class') as varchar) as comment from pg_class c
where relkind = 'r' and relname not like 'pg_%' and relname not like 'sql_%' order by relname
查询字段注释
select description from pg_description join pg_class on pg_description.objoid = pg_class.oid where relname = '表名'
本文介绍了如何在数据库中添加和查询表及字段的注释。通过`COMMENT ON`语句,可以方便地为表和字段添加描述性注释,提高数据库的可读性和维护性。同时,提供了查询表注释和字段注释的SQL查询语句,帮助开发者快速获取数据库对象的注释信息。

3800

被折叠的 条评论
为什么被折叠?



