How to see the table relationships in ORACLE - oracle

I had an Access database.
Now I have created a connection with this Access DB and copied it to ORACLE.
I hope the keys and constraints must be recreated in Oracle.
I couldn't find out how to create the relationships between the tables.
And also visualizing them.

First of all your db keys and constraints should be maintained if you have completed migration from Access DB to Oracle successfully.
Having said that, there are products for Oracle database that will help you to visualize table relationships. There is a product called "PL/SQL Developer by Allround Automations", which we use as company, that includes this in their GUI interface - they have both "foreign keys" and "foreign key references" branches in their navigation tree for a table node (The product is not free though..). You can check here for detailed information about the 'Diagram Window' feature of PL/SQL Developer.
Secondly Oracle's SQL Developer (which is free) has a feature called 'Data Modeling' for visual representation of displaying the Relational. Check here for Oracle SQL Developer's Data Modeling.
Furthermore if you want to find out the tables that have references to a specific table you can also use the following query:
select table_name from user_constraints
where r_constraint_name in
(select constraint_name
from user_constraints
where constraint_type in ('P','U')
and table_name = upper('&tableOfInterest')
)

I recommend getting Oracle SQL Developer. It is a free tool from Oracle that allows you to view and modify your database within a GUI. It also has a data modeler built in. It is also free (you just need to have Oracle first)

Related

Exploring Primary Key and Foreign Key in order to Construct ERD

I just imported data into an oracle database from a dump file. But I want to know constraints to enable me to make an Entity Relationship diagram and its links.
I used
select * from cat;
to get the description of each table. But this is not showing constraints and looks cumbersome to explore all tables like this.
You should query USER_CONSTRAINTS and USER_CONS_COLUMNS to find such a data.
Also, if you use DBMS_METADATA.GET_DDL (see documentation), you'll be able to extract DDL used to create tables & constraints.
However, consider using a GUI tool which enables you to "draw" tables and automatically queries metadata in order to graphically display information you're interested in. One of these is TOAD which, in its "Database - Report" menu offers the "ER diagram". I believe some other tools have it as well.

Can EF6 use oracle database links?

We have a legacy app that I am rewriting in .net. All of our databases are oracle and make use of database links. Is there any way for Entity Framework 6 to generate models based on tables located on a different database?
Currently the legacy app gets data from table like this
SELECT * FROM emp#foo2;
where its db connection is to database foo that has a database link to the database foo2.
I would like to reproduce this using EF6. So far all I have found regarding this is this question.
You can do two things that EF 4 or higher will work with:
CREATE VIEW EMP as SELECT * FROM emp#foo2;
CREATE MATERIALIZED VIEW EMP as SELECT * FROM emp#foo2;
LOBS are not accessible across a database link without some contorted PL/SQL processing to read the LOB piece by piece.
I believe fast refresh does not work across database links so you must consider the size of the table on the linked database. If you are refreshing a million rows you may find the time to do this is an issue. Most large tables are full of tombstone data that never changes so a timestamp column with the last modified date could help you create a package that only picks out the changed data.
If you are doing complicated joins for either ensure that Oracle considers the column that would be the primary key as not null.
You can add a primary key on views and materialized view but it must be disabled. See here for details.

Crystal Reports not returning data from some Oracle views using Oracle driver

I'm using Crystal Reports 2013 and have Oracle ODAC 32 and 64 bit versions installed. If I create a new report and use the "Oracle Server" data source, I can select from any tables to which I have access. However, I find I retrieve no data from some, not all, views.
The queries work fine in SQL Plus or SQL Developer. The queries retrieve data in Crystal Reports using outdated drivers like OLE DB and ODBC.
I can't find a commonality between the views that do or don't work. All the views I've tested with belong to the same schema. they all involve tables that belong to a third schema -- that is, I log in as USER1, query from a view belonging to USER2, which pulls data from tables belonging to USER2 and USER3. In order to create a view on a table and make that view available to others, Oracle requires SELECT WITH GRANT OPTION permission, which is in place. Again, the queries work fine in other SQL tools.
UPDATE: I've tried logging in as the owner of the views and was unable to query them. I've tried querying the underlying tables as the view owner (user2) and as the Crystal Reports owner (user1). Both users are able to query the underlying tables. The view itself seems to be the problem.
I'm studying the differences between the views that work and the views that don't work. I was optimistic when I found that the views that don't work were all using ORDER BY clauses that referenced column position (ex: ORDER BY 2, 1). I tried rewriting the ORDER BY to use column names. Didn't work. Tried removing the ORDER BY clauses. Didn't work. Back to the drawing board.
I found that the problem was that the Oracle view was using Oracle-specific, non-standard SQL. In addition to the ORDER BY 2, 1 mentioned above, there was an implicit date conversion in the WHERE clause e.g.
WHERE date_col = '01-JAN-2016'
When I added the TO_DATE function:
WHERE date_col = TO_DATE ('01-JAN-2016', 'dd-MON-yyyy')
Crystal Report was able to query the view.

oracle 11g dispaly user created tables

Hi I m new to oracle using 11g exprs edition and familiar with mysql. We can use the below code to display all databases in mysql
show databases;
What is the corresponding command in Oracle. Or how can i display all databases. Also We have
use mydatabase;
to chanage database in mysql. How can i change database in oracle. I tried to display all owners and their tables using the following command
select table_name, owner from all_tables;
It working fine. But when I tried to display tables I have created, by adding a where cluase
select table_name, owner from all_tables where owner='root';
it shows no rows were selected. Why this happens? Also I am facing the same problem with most of the queries when using the where clause. Without where clause it works fine. but when using it, the result is no rows selected for example
select * from all_tab_comments where owner='root';
select constraint_name, constraint_type from user_constraints where table_name='location';
Is there anything special in oracle for where clause or the problem with my query.
Your username is very unlikely to be root; it could however be ROOT, in which case you could do:
select table_name, owner from all_tables where owner='ROOT';
The owner name is case-sensitive, and all objects including users and table names are upper-case by default (unless they're created with double-quotes, which is a bad idea). If you're connected as that user, to see only your own tables you can also do:
select table_name from user_tables;
And there is the dba_tables view which also shows you tables you don't have permissions on, but you can only see that with elevated privileges.
Oracle doesn't have 'databases' in the same sense as other products. You probably means schemas, as the logical grouping of objects. And schemas and users are essentially synonymous.
To get a list of all schemas you can query dba_users (if you have the right privileges), or to get a list of schemas that have objects - as you may have users who only use objects in other schemas - you can do:
select distinct owner from dba_objects;
... or all_objects to again only see things you have permissions for. To see what kind of objects:
select owner, object_type, count(*) from dba_objects group by owner, object_type;
The documentation explains the static data dictionary views which hold all of this information. You won't be able to see all of them though, unless you're connected as a privileged user.
There will be a lot of differences between the two products; you might be better off trying to find a tutorial that works through them rather than using trial and error and trying to understand what's gone wrong at each step. Or at least familiarise yourself with the Oracle documentation so you can research issues.
First, there is going to be a terminology difference when you change platforms. What MySQL calls a "database" is most similar to what Oracle calls a "schema". If you are using Oracle XE, you can only have one database (using Oracle terminology) on the machine. You can have many schemas within that database.
The owner in all_tables is the name of the schema that owns the table. Assuming that you created an Oracle user root (which seems like an odd choice for a database user) and assuming that you did not create a case-sensitive user name in all lower case (which would create a ton of issues down the line), the owner will always be upper-case.
SELECT owner, table_name
FROM all_tables
WHERE owner = 'ROOT'
In Oracle, you do not generally change from one schema to another. You either fully qualify the table name
SELECT *
FROM schema_name.table_name
or you create synonyms (public or private) for objects that you want to reference
CREATE SYNONYM synonym_name
FOR schema_name.table_name;
SELECT *
FROM synonym_name
If you really want to, however, you can change your current schema for name resolution purposes
ALTER SESSION SET current_schema = <<schema name>>
use the view : tabs
select * from tabs;

Script to compare Oracle Schema with Teradata Views

I have a task to compare some Teradata Views with actual Oracle Tables.
I need a script for that.I have taken Java approach in which I connect to a specific schema from Oracle and then call the SELECT * FROM all_tables order by TABLE_NAME query and write this into a file.
I do the same for other schema but now my problem is Teradata.
Can you people please suggest me some script or query by which I can get proper details like it does with Oracle.
There is no complex Java Code but if you still want I can post it.
Edited:
Okay now I have a schema in Oracle which has all the tables.so views for those tables are created in Teredata.
I have to compare oracle tables and Teradata views every morning and send the differances.
So I use SELECT * FROM all_tables order by TABLE_NAME in Oracle and for Teradata I use SELECT * FROM dbc.tables WHERE tablekind='V' AND databasename='SCHEMA' order by TableName so now when I compare them I dont get accurate results, so I wanted to know does any script exists or how do I approach.
If your question is "How can I programmatically determine the structure of a view in Teradata?", then this should be a step in the right direction: HELP VIEW yourviewname;.
To get a list of views on a given table:
SELECT TableName
FROM DBC.Tables
WHERE Tablekind = 'V'
AND requestText LIKE '%yourtablename%'
GROUP BY 1
ORDER BY 1;
This information was gleaned from the official Teradata forums. You might also be interested in the Teradata users manuals. (Select your release version on the top right.)

Resources