我做类似的事情。我直接从 Oracle DB 中通过 OPENQUERY 语句从 SQL Server 读取这些内容,并将结果保存到 SQL Server 表中,以便分析历史比较架构信息和更改。
因此,您对以下查询的结果集要做的就是以某种方式(定期)存储它们,并向其中添加某种唯一/主键或时间戳,以便区分不同的扫描。
撇开 SQL Server 特定的代码,这些是我目前使用的基本 oracle sql 查询:
--Tables
SELECT table_name, owner, Tablespace_name, Num_Rows
FROM all_tables WHERE tablespace_name is not NULL
AND owner not in ('SYS', 'SYSTEM')
ORDER BY owner, table_name;
--Columns
SLECT OWNER, TABLE_NAME, Column_name, Data_type, data_length, data_precision, NULLABLE, character_Set_Name
From all_tab_cols
where USER_GENERATED = 'YES'
AND owner not in ('SYS', 'SYSTEM');
--Indexes
select Owner, index_name, table_name, uniqueness,BLEVEL,STATUS from ALL_INDEXES
WHERE owner not in ('SYS', 'SYSTEM')
--Constraints
select owner, constraint_name, constraint_type, table_name, search_condition, status, index_name, index_owner
From all_constraints
WHERE generated = 'USER NAME'
AND owner not in ('SYS', 'SYSTEM')
--Role Previleges
select grantee, granted_role, admin_option, delegate_option, default_role, common
From DBA_ROLE_PRIVS
--Sys Privileges
select grantee, privilege, admin_option, common
From DBA_SYS_PRIVS