查询表注释,包括表名,表备注,列名,列备注,导出表注释

本文介绍了如何使用SQL语句查询Oracle数据库中表和列的注释信息。通过`user_tab_comments`和`dba_col_comments`视图可以分别获取表和列的注释。同时提供了一个关联查询的例子,结合`owner`、`table_name`和`column_name`来获取完整的注释详情。对于mySQL数据库,推荐使用SQLyog工具进行导出。
摘要由CSDN通过智能技术生成

查询表注释,包括表名,表备注,列名,列备注

  1. 查看表注释
select * from user_tab_comments;
  1. 查看列注释
select * from dba_col_comments;
  1. 关联查询
select t.OWNER,t.TABLE_NAME 表名,b.comments 表备注,t.column_name 列名,t.comments 列备注 
from  dba_col_comments t 
left join user_tab_comments b
on b.TABLE_NAME = t.TABLE_NAME
where t.OWNER = '用户名';

SQL运行导出即可。

  1. mySQL数据库可以使用SQLyog导出
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
可以使用如下的SQL语句来获取dwd库中所有的信息: ``` SELECT table_name, table_comment FROM information_schema.tables WHERE table_schema = 'dwd' ``` 这个语句会返回dwd库中所有表名注释。 接下来,可以使用以下的SQL语句来获取每个的字段名和字段注释: ``` SELECT column_name, column_comment FROM information_schema.columns WHERE table_schema = 'dwd' AND table_name = '表名' ``` 将上面的SQL语句中的“表名”替换成具体的表名,就可以获取该的所有字段名和字段注释。 如果需要将所有的信息都导出来,可以使用脚本来自动化执行以上的SQL查询,并将结果保存到文件中。以下是一个Python脚本的示例: ``` import pymysql # 连接数据库 db = pymysql.connect(host='localhost', user='root', password='密码', db='dwd') # 获取所有的信息 cursor = db.cursor() cursor.execute("SELECT table_name, table_comment FROM information_schema.tables WHERE table_schema = 'dwd'") tables = cursor.fetchall() # 获取每个的字段信息并输出到文件 with open('output.txt', 'w', encoding='utf-8') as f: for table in tables: table_name = table[0] table_comment = table[1] f.write(f'Table Name: {table_name}\nTable Comment: {table_comment}\n') cursor.execute(f"SELECT column_name, column_comment FROM information_schema.columns WHERE table_schema = 'dwd' AND table_name = '{table_name}'") columns = cursor.fetchall() for column in columns: column_name = column[0] column_comment = column[1] f.write(f'Column Name: {column_name}\nColumn Comment: {column_comment}\n') f.write('\n') # 关闭数据库连接 db.close() ``` 这个脚本会将所有的信息输出到一个名为“output.txt”的文件中。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

怪异的bug

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值