I could not find all tables equivalent in oracle. Such as;
sys.index_columns
sys.columns
sys.foreign_key_columns
Is there any list to find out these table names? We have several queries in mssql and they are needed to be convert for oracle.
I could not find all tables equivalent in oracle. Such as;
sys.index_columns
sys.columns
sys.foreign_key_columns
Is there any list to find out these table names? We have several queries in mssql and they are needed to be convert for oracle.
You are looking for the 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
Instead of user_
(which is restricted to objects in your own schema), you could also use all_
for all objects you have access to or dba_
for all objects in the database (provided you have DBA authorisation).
The data dictonary tables are documented. See Static Data Dictionary Views
You are probably looking for the tables:
If that's any help, here's the SQL templates that I use in a "database browser" I built. It adapts itself following the RDBMS of the chosen database, and returns the exact same data into the application.
Here you have the queries to get:
SQL SERVER :
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
ORACLE
(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
SQL SERVER
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
ORACLE
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