Oracle 中的 Ms Sql sys 表等效
Ms Sql sys tables equivelant in Oracle
我无法在 oracle 中找到所有等同的 table。
如;
sys.index_columns
sys.columns
sys.foreign_key_columns
是否有任何列表可以找出这些 table 个名字?我们在 mssql 中有几个查询,需要将它们转换为 oracle。
您正在寻找 Oracle Data Dictionary。
MS SQL Oracle
------------------------ ------------------------------------------
sys.index_columns user_indexes and user_ind_columns
sys.columns user_tab_cols
sys.foreign_key_columns user_constraints and user_cons_columns
而不是 user_
(仅限于您自己架构中的对象),您还可以对您有权访问的所有对象使用 all_
或对所有对象使用 dba_
数据库(前提是你有DBA授权)。
数据字典表已记录。参见 Static Data Dictionary Views
您可能正在寻找以下表格:
- ALL_IND_COLUMNS
- ALL_TAB_COLUMNS
- ALL_CONS_COLUMNS
如果有任何帮助,这里是我在构建的 "database browser" 中使用的 SQL 模板。它根据所选数据库的 RDBMS 进行自我调整,并将 returns 完全相同的数据放入应用程序中。
这里有要获取的查询:
- table 和视图列表,包括来自统计信息的行数 table。
- table 的结构,包括索引列
Tables/Views 列表
SQL 服务器:
SELECT ta.tname, sc.name AS owner, ta.ttype, SUM(pa.rows) RowCnt
FROM
(
SELECT 'T' AS ttype, object_id, schema_id, name AS tname
FROM sys.tables
WHERE is_ms_shipped = 0 AND name LIKE '%{table_name_whatever}%'
UNION ALL
SELECT 'V' AS ttype, object_id, schema_id, name AS tname
FROM sys.views
WHERE is_ms_shipped = 0 AND name LIKE '%{table_name_whatever}%'
) ta
LEFT JOIN sys.partitions pa ON pa.OBJECT_ID = ta.OBJECT_ID AND pa.index_id IN (1,0)
LEFT JOIN sys.schemas sc ON ta.schema_id = sc.schema_id
GROUP BY ta.tname, sc.name, ta.ttype
ORDER BY ta.tname
甲骨文
(SELECT table_name as tname, owner, 'T' AS ttype, NUM_ROWS AS RowCnt FROM all_tables WHERE table_name LIKE '%{table_name_whatever}%')
UNION ALL
(SELECT view_name as tname, owner, 'V' AS ttype, NULL AS RowCnt FROM all_views WHERE view_name LIKE '%{table_name_whatever}%') ORDER BY tname
Table 结构(cols 和基本 idx)
SQL 服务器
SELECT c.name as column_name, ty.name AS type_name, c.max_length AS col_len,
(CASE
WHEN (i.name IS NOT NULL AND i.is_unique=1) THEN 'U'
WHEN (i.name IS NOT NULL AND i.is_unique=0) THEN 'X'
ELSE ''
END) AS idx,
'' as comments
FROM sys.columns c
INNER JOIN sys.objects o ON o.object_id=c.object_id
INNER JOIN sys.types ty ON c.system_type_id = ty.system_type_id AND ty.name<>'ID_Code'
LEFT JOIN sys.index_columns ic ON o.object_id = ic.object_id AND ic.column_id = c.column_id
LEFT JOIN sys.indexes i ON o.object_id = i.object_id AND i.index_id = ic.index_id
WHERE o.name = '{table_name_whatever}'
ORDER BY C.column_id
甲骨文
SELECT t.column_name, t.data_type as type_name, t.data_length as col_len,
(CASE
WHEN b.uniqueness='UNIQUE' THEN 'U'
WHEN b.uniqueness='NONUNIQUE' THEN 'X'
ELSE ''
END) AS idx,
c.comments
FROM all_tab_columns t
LEFT JOIN all_col_comments c ON c.table_name=t.table_name AND c.column_name = t.column_name
LEFT JOIN all_ind_columns a ON a.table_name=t.table_name AND a.column_name = t.column_name
LEFT JOIN all_indexes b ON a.index_name=b.index_name
WHERE t.table_name='{table_name_whatever}'
ORDER BY t.column_ID
我无法在 oracle 中找到所有等同的 table。 如;
sys.index_columns
sys.columns
sys.foreign_key_columns
是否有任何列表可以找出这些 table 个名字?我们在 mssql 中有几个查询,需要将它们转换为 oracle。
您正在寻找 Oracle Data Dictionary。
MS SQL Oracle
------------------------ ------------------------------------------
sys.index_columns user_indexes and user_ind_columns
sys.columns user_tab_cols
sys.foreign_key_columns user_constraints and user_cons_columns
而不是 user_
(仅限于您自己架构中的对象),您还可以对您有权访问的所有对象使用 all_
或对所有对象使用 dba_
数据库(前提是你有DBA授权)。
数据字典表已记录。参见 Static Data Dictionary Views
您可能正在寻找以下表格:
- ALL_IND_COLUMNS
- ALL_TAB_COLUMNS
- ALL_CONS_COLUMNS
如果有任何帮助,这里是我在构建的 "database browser" 中使用的 SQL 模板。它根据所选数据库的 RDBMS 进行自我调整,并将 returns 完全相同的数据放入应用程序中。
这里有要获取的查询:
- table 和视图列表,包括来自统计信息的行数 table。
- table 的结构,包括索引列
Tables/Views 列表
SQL 服务器:
SELECT ta.tname, sc.name AS owner, ta.ttype, SUM(pa.rows) RowCnt
FROM
(
SELECT 'T' AS ttype, object_id, schema_id, name AS tname
FROM sys.tables
WHERE is_ms_shipped = 0 AND name LIKE '%{table_name_whatever}%'
UNION ALL
SELECT 'V' AS ttype, object_id, schema_id, name AS tname
FROM sys.views
WHERE is_ms_shipped = 0 AND name LIKE '%{table_name_whatever}%'
) ta
LEFT JOIN sys.partitions pa ON pa.OBJECT_ID = ta.OBJECT_ID AND pa.index_id IN (1,0)
LEFT JOIN sys.schemas sc ON ta.schema_id = sc.schema_id
GROUP BY ta.tname, sc.name, ta.ttype
ORDER BY ta.tname
甲骨文
(SELECT table_name as tname, owner, 'T' AS ttype, NUM_ROWS AS RowCnt FROM all_tables WHERE table_name LIKE '%{table_name_whatever}%')
UNION ALL
(SELECT view_name as tname, owner, 'V' AS ttype, NULL AS RowCnt FROM all_views WHERE view_name LIKE '%{table_name_whatever}%') ORDER BY tname
Table 结构(cols 和基本 idx)
SQL 服务器
SELECT c.name as column_name, ty.name AS type_name, c.max_length AS col_len,
(CASE
WHEN (i.name IS NOT NULL AND i.is_unique=1) THEN 'U'
WHEN (i.name IS NOT NULL AND i.is_unique=0) THEN 'X'
ELSE ''
END) AS idx,
'' as comments
FROM sys.columns c
INNER JOIN sys.objects o ON o.object_id=c.object_id
INNER JOIN sys.types ty ON c.system_type_id = ty.system_type_id AND ty.name<>'ID_Code'
LEFT JOIN sys.index_columns ic ON o.object_id = ic.object_id AND ic.column_id = c.column_id
LEFT JOIN sys.indexes i ON o.object_id = i.object_id AND i.index_id = ic.index_id
WHERE o.name = '{table_name_whatever}'
ORDER BY C.column_id
甲骨文
SELECT t.column_name, t.data_type as type_name, t.data_length as col_len,
(CASE
WHEN b.uniqueness='UNIQUE' THEN 'U'
WHEN b.uniqueness='NONUNIQUE' THEN 'X'
ELSE ''
END) AS idx,
c.comments
FROM all_tab_columns t
LEFT JOIN all_col_comments c ON c.table_name=t.table_name AND c.column_name = t.column_name
LEFT JOIN all_ind_columns a ON a.table_name=t.table_name AND a.column_name = t.column_name
LEFT JOIN all_indexes b ON a.index_name=b.index_name
WHERE t.table_name='{table_name_whatever}'
ORDER BY t.column_ID