Exploring Primary Key and Foreign Key in order to Construct ERD - oracle

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.

Related

Searching from all tables in oracle

I am developing a java app which can connect to oracle database and selecting column names from any tables, after selecting columns i have to query the data from those tables which the user select in my java app, now my question is how can i join all tables in the database so that query returns data successfully, i want to connect to any oracle schema to a specific, i will make the logic in java, but i am unable to find the query which can extract the data from all tables, i tried natural join among all tables but it has dependency of having same name of connecting columns. so i want to know any generic way which can work in all conditions.
As others have mentioned.. it seems that there are other tools out there that you probably should leverage prior to trying to roll your own complex solution.
With that said if you wish to roll your own solution you could look into using some of oracle's dictionary tables. Such as:
Select * from all_tables;
Select * from all_tab_cols;

Selection of table (or view) in oracle, that I cannot find in TOAD

I am reverse-engineering an application which administers an Oracle database.
Everything is new to me (application + database)
There is a statement there somewhere, which is:
SELECT * FROM XXX#YYY (XXX is a word, YYY another word)
If I go into my database with TOAD I can't find an 'XXX#YYY' table nor view. If I copy paste the statement in TOAD's editor, I get results as if the table exists.
I know that the '#' symbol is allowed for naming an Oracle object. Is it possible that it means something else here though?
How can I find the table (or view)? Is it possible to get information through a statement such as which schema does 'XXX#YYY' belong to or weather it is a table or a view, so that I can track it?
The database consists of many schemas. There is a default one. Is it possible that XXX#YYY may belong to another schema, rather than the default?
Please help me find the table.
Identifier behind # is database link. It is a way to access objects on some remote Oracle server. more info on http://docs.oracle.com/cd/E11882_01/server.112/e26088/statements_5005.htm#SQLRF01205
In Toad/Oracle XXX#YYY means object#database_link.
Look for the schema in your DB, there you will find the table.
Btw: I think its better to use SCHEMA.TABLENAME
If you have problems finding the SCHEMA, go to View->Toad Options, select Treeview at Browser style and then it should display all schemas.

Oracle Data Modeler: add initial data to tables

I've created a relational model in Oracle SQL Developer Data Modeler.
I want to add predefined\static data that should exist in the initial clean database: enum values, fixed lists( for example: contries ) using modeler. My goal is to receive script using "DDL File Editor" tool which contains not only "create table" commands and so on, but also "inserts" with initial data.
I there any way to do this?
What might be the easiest way would be to put the DML into the AFTER CREATE tab under Scripts for each table - and to make sure it's included in the DDL script.

How to see the table relationships in 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)

Script Oracle tables (DDL) with data insert statements into single/multiple sql files

I am needing to export the tables for a given schema, into DDL scripts and Insert statements - and have it scripted such that, the order of dependencies/constraints is maintained.
I came across this article suggesting how to archive the database with data - http://www.dba-oracle.com/t_archiving_data_in_file_structures.htm - not sure if the article is applicable for oracle 10g/11g.
I have seen "export table with data" features in "Sql Developer", "Toad for Oracle", "DreamCoder for Oracle" etc, but i would need to do this one table at a time, and will still need to figure out the right order of script execution manually.
Are there any tools/scripts that can utilize oracle metadata and generate DDL script with data?
Note that some of the tables have CLOB datatype columns - so the tool/script would need to be able to handle these columns.
P.S. I am needing something similar to the "Generate Scripts" feature in SQL Server 2008, where one can specify "script data" option and get back a self-sufficient script with DDL and data, generated in the order of table constraints. Please see: http://www.kodyaz.com/articles/sql-server-script-data-with-generate-script-wizard.aspx
Thanks for your help!
Firstly, recognise that this isn't necessarily possible. A view can use a function in a package that also selects from the view. Another issue is that you might need to load data into tables and then apply constraints, even though this might be slower than the other way round.
In short, you will need to do some work here.
Work out the dependencies in your system. ALL_DEPENDENCIES is the primary mechanism.
Then use DBMS_METADATA.GET_DDL to extract the DDL statements. For small data volumes, I'd extract the constraints separately for applying after the data load.
In current versions you can create external tables to unload data from regular tables into OS files (and obviously go the other way round). But if you've got exotic datatypes (BLOB, RAW, XMLTYPEs, User Defined Types....) it will be more challenging.
I suggest that you use Oracle standard export and import (exp/imp) here, is there a reason why you won't consider it? Note in addition you can use the "indexfile" option on the import to output the SQL statements (unfortunately this doesn't include the inserts) to a file instead of actually executing them.

Resources