2023-12-06 14:50:02 +08:00
|
|
|
--DM_DB_SCHEMAS 库schemas
|
|
|
|
|
select
|
2023-12-13 15:11:26 +08:00
|
|
|
distinct owner as SCHEMA_NAME
|
2024-01-05 05:31:32 +00:00
|
|
|
from all_objects
|
2024-01-15 11:55:59 +00:00
|
|
|
order by owner
|
2023-12-06 14:50:02 +08:00
|
|
|
---------------------------------------
|
|
|
|
|
--DM_TABLE_INFO 表详细信息
|
2023-12-13 21:42:06 +08:00
|
|
|
SELECT a.object_name as TABLE_NAME,
|
|
|
|
|
b.comments as TABLE_COMMENT,
|
|
|
|
|
a.created as CREATE_TIME,
|
|
|
|
|
TABLE_USED_SPACE(
|
|
|
|
|
(SELECT SF_GET_SCHEMA_NAME_BY_ID(CURRENT_SCHID)),
|
|
|
|
|
a.object_name
|
|
|
|
|
) * page() as DATA_LENGTH,
|
|
|
|
|
(SELECT sum(INDEX_USED_PAGES(id))* page()
|
|
|
|
|
FROM SYSOBJECTS
|
|
|
|
|
WHERE NAME IN (SELECT INDEX_NAME
|
2024-01-05 05:31:32 +00:00
|
|
|
FROM ALL_INDEXES
|
2023-12-13 21:42:06 +08:00
|
|
|
WHERE OWNER = 'wxb'
|
|
|
|
|
AND TABLE_NAME = a.object_name)) as INDEX_LENGTH,
|
|
|
|
|
c.num_rows as TABLE_ROWS
|
|
|
|
|
|
2024-01-05 05:31:32 +00:00
|
|
|
FROM all_objects a
|
|
|
|
|
LEFT JOIN ALL_TAB_COMMENTS b ON b.TABLE_TYPE = 'TABLE'
|
2023-12-13 21:42:06 +08:00
|
|
|
AND a.object_name = b.TABLE_NAME
|
|
|
|
|
AND b.owner = a.owner
|
2024-01-05 05:31:32 +00:00
|
|
|
LEFT JOIN (SELECT a.owner, a.table_name, a.num_rows FROM all_tables a) c
|
2023-12-13 21:42:06 +08:00
|
|
|
ON c.owner = a.owner AND c.table_name = a.object_name
|
|
|
|
|
|
|
|
|
|
WHERE a.owner = (SELECT SF_GET_SCHEMA_NAME_BY_ID(CURRENT_SCHID))
|
|
|
|
|
AND a.object_type = 'TABLE'
|
|
|
|
|
AND a.status = 'VALID'
|
2024-01-15 11:55:59 +00:00
|
|
|
ORDER BY a.object_name
|
2023-12-06 14:50:02 +08:00
|
|
|
---------------------------------------
|
|
|
|
|
--DM_INDEX_INFO 表索引信息
|
2023-12-07 10:03:50 +08:00
|
|
|
select
|
2023-12-13 15:11:26 +08:00
|
|
|
a.index_name as INDEX_NAME,
|
|
|
|
|
a.index_type as INDEX_TYPE,
|
2024-01-29 04:20:23 +00:00
|
|
|
case when a.uniqueness = 'UNIQUE' then 1 else 0 end as IS_UNIQUE,
|
2023-12-13 15:11:26 +08:00
|
|
|
indexdef(b.object_id,1) as INDEX_DEF,
|
|
|
|
|
c.column_name as COLUMN_NAME,
|
|
|
|
|
c.column_position as SEQ_IN_INDEX,
|
|
|
|
|
'无' as INDEX_COMMENT
|
2024-01-05 05:31:32 +00:00
|
|
|
FROM ALL_INDEXES a
|
|
|
|
|
LEFT JOIN all_objects b on a.owner = b.owner and b.object_name = a.index_name and b.object_type = 'INDEX'
|
|
|
|
|
LEFT JOIN ALL_IND_COLUMNS c
|
|
|
|
|
on a.owner = c.table_owner and a.index_name = c.index_name and a.TABLE_NAME = c.table_name
|
2023-12-07 10:03:50 +08:00
|
|
|
|
2023-12-07 17:32:32 +08:00
|
|
|
WHERE a.owner = (SELECT SF_GET_SCHEMA_NAME_BY_ID(CURRENT_SCHID))
|
|
|
|
|
and a.TABLE_NAME = '%s'
|
|
|
|
|
and indexdef(b.object_id,1) != '禁止查看系统定义的索引信息'
|
2023-12-07 10:03:50 +08:00
|
|
|
order by a.TABLE_NAME, a.index_name, c.column_position asc
|
2023-12-06 14:50:02 +08:00
|
|
|
---------------------------------------
|
|
|
|
|
--DM_COLUMN_MA 表列信息
|
2023-12-13 15:11:26 +08:00
|
|
|
select a.table_name as TABLE_NAME,
|
|
|
|
|
a.column_name as COLUMN_NAME,
|
|
|
|
|
case when a.NULLABLE = 'Y' then 'YES' when a.NULLABLE = 'N' then 'NO' else 'NO' end as NULLABLE,
|
2023-12-06 14:50:02 +08:00
|
|
|
case
|
|
|
|
|
when a.char_col_decl_length > 0 then concat(a.data_type, '(', a.char_col_decl_length, ')')
|
|
|
|
|
when a.data_precision > 0 and a.data_scale > 0
|
|
|
|
|
then concat(a.data_type, '(', a.data_precision, ',', a.data_scale, ')')
|
|
|
|
|
else a.data_type end
|
2023-12-13 15:11:26 +08:00
|
|
|
as COLUMN_TYPE,
|
|
|
|
|
b.comments as COLUMN_COMMENT,
|
|
|
|
|
a.data_default as COLUMN_DEFAULT,
|
|
|
|
|
a.data_scale as NUM_SCALE,
|
2024-01-29 04:20:23 +00:00
|
|
|
case when t.COL_NAME = a.column_name then 1 else 0 end as IS_IDENTITY,
|
|
|
|
|
case when t2.constraint_type = 'P' then 1 else 0 end as IS_PRIMARY_KEY
|
2024-01-05 05:31:32 +00:00
|
|
|
from all_tab_columns a
|
2023-12-13 15:11:26 +08:00
|
|
|
left join user_col_comments b
|
2024-01-29 04:20:23 +00:00
|
|
|
on b.owner = (SELECT SF_GET_SCHEMA_NAME_BY_ID(CURRENT_SCHID))
|
|
|
|
|
and b.table_name = a.table_name
|
|
|
|
|
and a.column_name = b.column_name
|
|
|
|
|
left join (select b.owner, b.TABLE_NAME, a.NAME as COL_NAME
|
2023-12-13 15:11:26 +08:00
|
|
|
from SYS.SYSCOLUMNS a,
|
2024-01-29 04:20:23 +00:00
|
|
|
SYS.all_tables b,
|
|
|
|
|
SYS.SYSOBJECTS c
|
2023-12-13 15:11:26 +08:00
|
|
|
where a.INFO2 & 0x01 = 0x01
|
2024-01-29 04:20:23 +00:00
|
|
|
and a.ID = c.ID
|
|
|
|
|
and c.NAME = b.TABLE_NAME) t
|
|
|
|
|
on t.table_name = a.table_name and t.owner = a.owner
|
|
|
|
|
left join (select uc.OWNER, uic.column_name, uic.table_name, uc.constraint_type
|
|
|
|
|
from user_ind_columns uic
|
|
|
|
|
left join user_constraints uc on uic.index_name = uc.index_name) t2
|
|
|
|
|
on t2.table_name = t.table_name and a.column_name = t2.column_name
|
2023-12-06 14:50:02 +08:00
|
|
|
where a.owner = (SELECT SF_GET_SCHEMA_NAME_BY_ID(CURRENT_SCHID))
|
|
|
|
|
and a.table_name in (%s)
|
2024-01-29 04:20:23 +00:00
|
|
|
order by a.table_name,
|
|
|
|
|
a.column_id
|