达梦数据库查询表字段信息
本文于 5 天前发布,最后更新于 5 天前

本文只记录一条SQL:最全的表字段信息查询

SELECT 
DT.OWNER 用户名,
DT.TABLE_NAME 表名,
DT.TABLE_COMMENTS 表注释,
DT.TABLESPACE_NAME 所属表空间,
DT.TABLE_PK 表主键,
DTC.COLUMN_NAME 字段名,
CASE 
WHEN DTC.DATA_PRECISION IS NOT NULL AND DTC.DATA_SCALE IS NOT NULL THEN DTC.DATA_TYPE||'('||DTC.DATA_PRECISION||','||DTC.DATA_SCALE||')'
WHEN DTC.DATA_TYPE LIKE '%TIME%' THEN DTC.DATA_TYPE||'('||DTC.DATA_SCALE||')'
WHEN DATA_TYPE LIKE '%INT%' OR DATA_TYPE IN ('BIT','BLOB','CLOB','TEXT','DATE','IMAGE','LONGVARCHAR') THEN DATA_TYPE
ELSE DTC.DATA_TYPE||'('||DTC.DATA_LENGTH||')'
END 字段类型,
CC.COMMENTS 字段注释,
CASE WHEN DIC.COLUMN_NAME IS NULL THEN '否' ELSE '是' END 是否有索引,
CASE WHEN DTC.NULLABLE='N' THEN '否' ELSE '是' END 是否可为空,
DTC.DATA_DEFAULT 默认值
FROM(
SELECT 
DT.OWNER OWNER,
DT.TABLE_NAME TABLE_NAME,
TC.COMMENTS TABLE_COMMENTS,
DT.TABLESPACE_NAME TABLESPACE_NAME,
LISTAGG(DCC.COLUMN_NAME,',') WITHIN GROUP (ORDER BY POSITION) TABLE_PK
FROM DBA_TABLES DT
LEFT JOIN DBA_TAB_COMMENTS TC ON DT.OWNER=TC.OWNER AND DT.TABLE_NAME=TC.TABLE_NAME
LEFT JOIN DBA_CONSTRAINTS DC ON DT.OWNER=DC.OWNER AND DT.TABLE_NAME=DC.TABLE_NAME AND DC.CONSTRAINT_TYPE='P'
LEFT JOIN DBA_CONS_COLUMNS DCC ON DC.CONSTRAINT_NAME=DCC.CONSTRAINT_NAME
WHERE DT.OWNER='用户名' 
GROUP BY DT.OWNER,DT.TABLE_NAME,TC.COMMENTS,DT.TABLESPACE_NAME
)DT
LEFT JOIN DBA_TAB_COLUMNS DTC ON DT.OWNER=DTC.OWNER AND DT.TABLE_NAME=DTC.TABLE_NAME
LEFT JOIN DBA_COL_COMMENTS CC ON DTC.OWNER=CC.OWNER AND DTC.TABLE_NAME=CC.TABLE_NAME AND DTC.COLUMN_NAME=CC.COLUMN_NAME
LEFT JOIN (SELECT DISTINCT INDEX_OWNER,TABLE_OWNER,TABLE_NAME,COLUMN_NAME FROM DBA_IND_COLUMNS)DIC 
ON DTC.OWNER=DIC.TABLE_OWNER AND DTC.TABLE_NAME=DIC.TABLE_NAME AND DTC.COLUMN_NAME=DIC.COLUMN_NAME
ORDER BY DT.OWNER,DT.TABLE_NAME;
暂无评论

发送评论 编辑评论


|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇