Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

达梦数据库获取表设计 #73

Open
toplhy opened this issue Oct 22, 2024 · 0 comments
Open

达梦数据库获取表设计 #73

toplhy opened this issue Oct 22, 2024 · 0 comments

Comments

@toplhy
Copy link
Owner

toplhy commented Oct 22, 2024

1. 查询模式下所有表

SELECT T.TABLE_NAME, C.COMMENTS
FROM DBA_TABLES T
LEFT JOIN ALL_TAB_COMMENTS C ON (C.OWNER = T.OWNER AND C.TABLE_NAME = T.TABLE_NAME)
WHERE T.OWNER = '具体模式名'
ORDER BY T.TABLE_NAME ASC;

2. 查询表字段设计

SELECT COL.COLUMN_NAME "字段名称",
       COL.DATA_TYPE "字段类型",
       COL.DATA_LENGTH "字段长度",
       (CASE WHEN NULLABLE = 'N' THEN '' ELSE '' END) "是否为空",
       COM.COMMENTS "字段描述"
FROM DBA_TAB_COLUMNS COL
LEFT JOIN DBA_COL_COMMENTS COM ON (COM.OWNER = COL.OWNER AND COM.TABLE_NAME = COL.TABLE_NAME AND COM.COLUMN_NAME = COL.COLUMN_NAME)
WHERE COL.OWNER = '具体模式名'
  AND COL.TABLE_NAME = '具体表名';

3. 整体查询

SELECT T.TABLE_NAME "表名",
       C.COMMENTS "表注释",
       COL.COLUMN_NAME "字段名称",
       COL.DATA_TYPE "字段类型",
       COL.DATA_LENGTH "字段长度",
       (CASE WHEN NULLABLE = 'N' THEN '' ELSE '' END) "是否为空",
       COM.COMMENTS "字段描述"
FROM DBA_TABLES T
LEFT JOIN ALL_TAB_COMMENTS C ON (C.OWNER = T.OWNER AND C.TABLE_NAME = T.TABLE_NAME)
LEFT JOIN DBA_TAB_COLUMNS COL ON (COL.OWNER = T.OWNER AND COL.TABLE_NAME = T.TABLE_NAME)
LEFT JOIN DBA_COL_COMMENTS COM ON (COM.OWNER = COL.OWNER AND COM.TABLE_NAME = COL.TABLE_NAME AND COM.COLUMN_NAME = COL.COLUMN_NAME)
WHERE T.OWNER = '具体模式名'
ORDER BY T.TABLE_NAME ASC, COL.COLUMN_ID ASC;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant