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

oracle获取当前用户表、字段等详细信息SQL

发布时间:2020-12-12 16:59:16 所属栏目:百科 来源:网络整理
导读:做个笔记,仅供参考 decode(a.NULLABLE,'Y','0','1') notNull,//是否允许空 COALESCE(m.COMMENTS,' ') comments,//字段备注 decode(k.uniqueness,'UNIQUE','1','0') uniques,//是否唯一 COALESCE(k.index_name,' ') indexName,//如果是索引,索引名 decode(k

做个笔记,仅供参考

decode(a.NULLABLE,'Y','0','1') notNull,//是否允许空
COALESCE(m.COMMENTS,' ') comments,//字段备注
decode(k.uniqueness,'UNIQUE','1','0') uniques,//是否唯一
COALESCE(k.index_name,' ') indexName,//如果是索引,索引名
decode(k.key,'0') masterKey//是否主键
FROM
user_tab_columns a
INNER JOIN user_tables d on a.TABLE_NAME=d.TABLE_NAME
LEFT JOIN user_tab_comments t ON t.TABLE_NAME=d.TABLE_NAME
LEFT JOIN user_col_comments m ON m.COLUMN_NAME=a.COLUMN_NAME AND m.TABLE_NAME=d.TABLE_NAME
LEFT JOIN
(
SELECT e.index_name,u.TABLE_NAME,u.COLUMN_NAME,e.uniqueness,decode(p.constraint_name,NULL,'N','Y') key
from user_indexes e INNER JOIN user_ind_columns u ON e.index_name=u.index_name
LEFT JOIN ( select constraint_name from user_constraints where constraint_type='P' ) p ON e.index_name=p.constraint_name
) k ON k.TABLE_NAME=a.TABLE_NAME and k.COLUMN_NAME=a.COLUMN_NAME
ORDER BY tbName

备注:user_开头是当前用户,all_开头所有用户,dba_开头包括系统表

(编辑:李大同)

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

    推荐文章
      热点阅读