【SQL】如何获得表及字段的说明信息(comment)的创建脚本

写了一个简单实用的的SQL脚本,生成数据库中具体用户中的注释信息(COMMMENT)的创建脚本。记录在这里,方便查询和参考。
当迁移到测试数据库后发现注释信息均为乱码后可以使用这个方法快速的恢复。

1.查询表级别的注释信息
select 'COMMENT ON TABLE '||table_name||' IS '''||comments||''';' from user_tab_comments;

2.查询表中列的注释信息
select 'COMMENT ON COLUMN '||table_name||'.'||COLUMN_NAME||' IS '''||COMMENTS||''';' from user_col_comments;

以上提到了两个视图,一个是user_tab_comments,另一个是user_col_comments,这两个视图分别记录了表一级别的和行一级别的注释信息。
oralce官方文档中是这样描述的:

ALL_TAB_COMMENTS

ALL_TAB_COMMENTS displays comments on the tables and views accessible to the current user.

Related Views

  • DBA_TAB_COMMENTS displays comments on all tables and views in the database.

  • USER_TAB_COMMENTS displays comments on the tables and views owned by the current user. This view does not display the OWNER column.

ColumnDatatypeNULLDescription
OWNERVARCHAR2(30)NOT NULLOwner of the object
TABLE_NAMEVARCHAR2(30)NOT NULLName of the object
TABLE_TYPEVARCHAR2(11)
Type of the object
COMMENTSVARCHAR2(4000)
Comment on the object

ALL_COL_COMMENTS

ALL_COL_COMMENTS displays comments on the columns of the tables and views accessible to the current user.

Related Views

  • DBA_COL_COMMENTS displays comments on the columns of all tables and views in the database.

  • USER_COL_COMMENTS displays comments on the columns of the tables and views owned by the current user. This view does not display the OWNER column.

ColumnDatatypeNULLDescription
OWNERVARCHAR2(30)NOT NULLOwner of the object
TABLE_NAMEVARCHAR2(30)NOT NULLName of the object
COLUMN_NAMEVARCHAR2(30)NOT NULLName of the column
COMMENTSVARCHAR2(4000)
Comment on the column


-- The End --

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/519536/viewspace-586836/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/519536/viewspace-586836/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值