Query to find all relationships between tables

Please help me wit the following
Query to find all relationships between tables
SAMPLE OUTPUT:
PRIMTAB PRIMCOL FOREIGNTAB FOREIGN KEY
DEPT DEPTNO EMP DEPTNO
Return all records in the database.
PLEASE HELP

SET LINESIZE 150
COLUMN primcol FORMAT A30
COLUMN foreigncol FORMAT A30
SELECT uc1.table_name AS primtab,
ucc1.column_name AS primcol,
uc2.table_name AS foreigntab,
ucc2.column_name AS foreigncol
FROM user_constraints uc1,
user_constraints uc2,
user_cons_columns ucc1,
user_cons_columns ucc2
WHERE uc1.constraint_name = uc2.r_constraint_name
AND uc1.constraint_name = ucc1.constraint_name
AND uc2.constraint_name = ucc2.constraint_name
AND ucc1.position = ucc2.position
ORDER BY uc1.table_name,
ucc1.position
/

Similar Messages

  • Find the relationship between tables where the constraint type is 'R'

    Hello,
    I am trying to find an answer of the following question:
    How to query the user_constraints view (probably some more views should be involved here) in order to get information about the table name, the column (or columns) that is (are) a foreign key to another table, the name of the referenced table, and the name of the referenced column (or columns) and finally the name of the FK. And additionally, if the referenced table from the first row has its own constraints of type 'R', then to have this table in the second row, where this same table stands in the first column. Each table that is a participant in this tree, of course, could have one or many FK to other tables. One does not know this at run time.
    A predicate to say with which table to start the search from will look like this:
    <pre>
    user_constraints.table_name = 'my_table_name'
    </pre>
    So, if you could help by providing at least hints for such a query, I will be glad to see different answers.
    Thanks :)

    Thanks a lot for the answer!
    That will work and is a very useful starting point.

  • SQL query to find differences (changes) between tables (from one table) where field names are different

    Hi All,
    I am looking to create a view which returns new or modified data (differences) based on a comparison between two tables.
    The EMP_SOURCE table stores all employee data including duplicate staff numbers (STAFFNO):
    CREATE TABLE [dbo].[EMP_SOURCE](
    [FULLNAME] [varchar](255) NULL,
    [JOBTITLE] [varchar](255) NULL,
    [LOCATION] [varchar](255) NULL,
    [COUNTRY] [varchar](255) NULL,
    [STAFFNO] [varchar](255) NULL
    ) ON [PRIMARY]
    GO
    The EMP table stores unique staff numbers. This is the table used by the application.
    CREATE TABLE [dbo].[EMP](
    [EMP_ID] [int] NOT NULL,
    [EMP_NAME] [varchar](255) NULL,
    [EMP_TITLE] [varchar](255) NULL,
    [EMP_OFFICE] [varchar](255) NULL,
    [EMP_COUNTRY] [varchar](255) NULL,
    [EMP_NUMBER] [varchar](255) NULL,
    CONSTRAINT [PK_EMP] PRIMARY KEY CLUSTERED
    [EMP_ID] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    We are looking to migrate data from EMP_SOURCE to EMP but only records which are new in EMP_SOURCE and do not exist in EMP or records which are different in EMP_SOURCE from EMP.
    EMP_SOURCE:
    FULLNAME
    JOBTITLE
    LOCATION
    COUNTRY
    STAFFNO
    John Smith
    Manager
    London
    UK
    1087
    Beth King
    Analyst
    New York
    USA
    2095
    Karl Bent
    Manager
    Chicago
    USA
    1106
    Beth King
    Junior
    Washington
    USA
    2095
    Harry Kline
    Consultant
    Manchester
    UK
    2341
    EMP:
    EMP_ID
    EMP_NAME
    EMP_TITLE
    EMP_OFFICE
    EMP_COUNTRY
    EMP_NUMBER
    1
    John Smith
    Manager
    London
    UK
    1087
    2
    Beth King
    Analyst
    New York
    USA
    2095
    3
    Karl Bent
    Manager
    Washington
    USA
    1106
    Based on the above comparison, EMP_SOURCE table has the following differences:
    FULLNAME
    JOBTITLE
    LOCATION
    COUNTRY
    STAFFNO
    Harry Kline
    Consultant
    Manchester
    UK
    2341
    Karl Bent
    Manager
    Chicago
    USA
    1106
    Differences in red. Beth King should be completely ignored because of duplicate staff numbers (EMP_NUMBER).
    Any help to create a view which returns only the differences from EMP_SOURCE would be appreciated.
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (1, 'John Smith', 'Manager', 'London', 'UK', '1087');
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (2, 'Beth King', 'Analyst', 'New York', 'USA', '2095');
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (3, 'Karl Bent', 'Manager', 'Washington', 'USA', '1106');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('John Smith', 'Manager', 'London', 'UK', '1087');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Beth King', 'Analyst', 'New York', 'USA', '2095');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Karl Bent', 'Manager', 'Chicago', 'USA', '1106');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Beth King', 'Junior', 'Washington', 'USA', '2095');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO) VALUES ('Harry Kline', 'Consultant', 'Manchester', 'UK', '2341');

    HI Manc !
    You may use the below code to get your desired output;
    CREATE TABLE [dbo].[EMP_SOURCE](
    [FULLNAME] [varchar](255) NULL,
    [JOBTITLE] [varchar](255) NULL,
    [LOCATION] [varchar](255) NULL,
    [COUNTRY] [varchar](255) NULL,
    [STAFFNO] [varchar](255) NULL
    GO
    CREATE TABLE [dbo].[EMP](
    [EMP_ID] [int] NOT NULL,
    [EMP_NAME] [varchar](255) NULL,
    [EMP_TITLE] [varchar](255) NULL,
    [EMP_OFFICE] [varchar](255) NULL,
    [EMP_COUNTRY] [varchar](255) NULL,
    [EMP_NUMBER] [varchar](255) NULL
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (1, 'John Smith', 'Manager', 'London', 'UK', '1087');
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (2, 'Beth King', 'Analyst', 'New York', 'USA', '2095');
    INSERT INTO EMP (EMP_ID, EMP_NAME, EMP_TITLE, EMP_OFFICE, EMP_COUNTRY, EMP_NUMBER)
    VALUES (3, 'Karl Bent', 'Manager', 'Washington', 'USA', '1106');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('John Smith', 'Manager', 'London', 'UK', '1087');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Beth King', 'Analyst', 'New York', 'USA', '2095');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Karl Bent', 'Manager', 'Chicago', 'USA', '1106');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO)
    VALUES ('Beth King', 'Junior', 'Washington', 'USA', '2095');
    INSERT INTO EMP_SOURCE (FULLNAME, JOBTITLE, LOCATION, COUNTRY, STAFFNO) VALUES ('Harry Kline', 'Consultant', 'Manchester', 'UK', '2341');
    SELECT FULLNAME,JOBTITLE,LOCATION,COUNTRY,STAFFNO FROM EMP_SOURCE
    EXCEPT
    SELECT EMP_NAME,EMP_TITLE,EMP_OFFICE,EMP_COUNTRY,EMP_NUMBER FROM Emp
    Please let me know if this doesn’t work for you. Hope I have answered you correctly.
    Thanks,
    Hasham

  • Query to find all zeroes in table

    Need a sql query to just display if  Column B contains zeros like (0000,000,00000,00000 etc..)
    Version:2005
    Table looks like this:
     A         B                  
      1         0000                 
      2         000                  
      3         000000               
      4         000011000            
      5         0000000sh6820090  
    s

    Sorry for not being clear, I have leading zeroes and i cant use your both queries. Column is alpha numeric, i just need to find Zeroes in the column
    excluding Nulls. Following bold values need to be pulled.
       A         B                  
      1         0000                 
      2         000agsn86755jdd000                  
      3         000sfdbg0001226               
      4         0000000            
      5         0000000sh6820090  
      6         0000dhsg1190000
      7         00000
      8         NULL
      9         00000xb7826000
      10        00
      11        00828jxjk0000
      12        0
      13        00sd000877jsnj   
    s

  • How to find the relationship between tables

    Hi All
    I am working in oracle apps R12 in OM and INV and i am new. Is there any document for getting the all key tables and the relationship of the tables.
    Thanks & Regards
    Srikkanth.M

    Hi;
    You need to check e-trm site to can see table explaniation,integrity,relations etc
    Check:
    etrm.oracle.com
    Regard
    Helios

  • In which table we can find the relationship between Role id and Task id

    Hi Experts,
    In which table we can find the relationship between Role id and Task id in Cprojects.
    Thanks
    Subhaskar

    Hi Subhaskar,
    Apart from DPR_ENTITY_LINK , you can also get it from table DPR_PART.
    Please go through the below link
    http://wiki.sdn.sap.com/wiki/display/PLM/cProjectstablesin+SAP
    I hope this will help you.
    Regards,
    Rahul

  • TRACING RELATIONSHIP BETWEEN TABLES....

    Hello all,
    I use the below query to find the hierarchial relationship between tables ...
    SELECT
    c.table_name parent_table , c.column_name parent_column,b.table_name child_table ,b.column_name child_COLUMN ,LEVEL lrv
    FROM USER_constraints a,user_cons_columns b ,user_cons_columns c
    WHERE a.constraint_name = b.constraint_name
    AND a.r_constraint_name = c.constraint_name
    AND constraint_type = 'R'
    AND b.table_name <> 'CNTRCT_PARENT'
    START WITH b.table_name = 'CNTRCT_PARENT'
    CONNECT BY NOCYCLE PRIOR b.table_name = c.table_name
    ORDER BY c.table_name
    but i need order like below,
    parent table childtable1
    childtable1 grantchildtable1
    childtable1 grantchildtable2
    parent table childtable2
    childtable2 grantchildtable1
    childtable2 grantchildtable2
    childtable2 grantchildtable3
    how this sort of order by is possible ...
    Thanks in advance
    Vijay G

    Hi,
    Try
    ORDER SIBLINGS BY ...

  • The best way to find the relationship in table especially for PS

    Hi All,
    How the fastest way to find the relationship between PS table with another table.
    For example table PROJ, PRPS with another table in FICO module...let say the table that store the transaction CJR2...WBS element link to Cost element or activity type...and material on it...
    please help.
    Cheers,
    Nies

    go to se38 select any report then click radio button attribute and double on logical data base write PSJ as logical data base for Project and select display structure. You will get all dependant table name in relevant sequence

  • Relationship between tables in a module(urgent)

    Hi ,
    Am new to this domain(SAP)...
    I want to move datas to SAP through codes...
    For example,i want to add datas to ItemGroups module of Inventory module....But it failed...On the other hand,i was able to add datas to Item table of the same module...
    i think there is someother table to which ItemGroups is related..Could anyone kindly help me in finding out these type of relationship between tables in a moduel at ease?
    Hoping for your quick reply,
    Thanks

    hi
    I think in your scnario data is fetching from material valuation table based on material number (MBEW-MATNR), through document segment material table (MSEG-MATNR).
    Based on you company material management flow, your scenario is based.
    hope this helps
    thank you.

  • Query to find all the view name and their size in GB

    Hi,
    What is the query to find all the view name and their size in GB.I am aware of joining all_views and user_segments but this is not serving the purpose.is there any table i need to join to get the desired result
    Thanks

    You could of course be thinking of views as they are stored in other RDBMS' as some of them actually create the view as a table on the database with a copy of the data in it and maintain that data as the base tables are updated.
    As already mentioned, Oracle just stores the SQL of the View and executes that SQL when the view is queried.
    Alternatively, Oracle also has "materialized views" which are created as snapshots of the data and will have a size. This data is updated (refreshed) based on the parameters used when creating the materialized view which means that it will either be, commonly, when a commit is issued or when a refresh is explicitly requested (refresh on demand).

  • How to find the relation between tables

    Hi
    I am working in Oracle R12
    How to find the relationship between these tables INV_MIN_MAX_TEMP,po_requisition_lines_all and Per_all_people_f
    These two table i have joined with po_requisition_lines_all and Per_all_people_f To_person_id from PO and Person from hr table but i cant able to join this table with other tables INV_MIN_MAX_TEMP
    regards
    Srikkanth

    Hi;
    Please check e-trm site for table relation,integration,explanation etc..
    etrm.oracle.com/
    Regard
    Helios

  • Sql query to find all contacts for an account

    I wonder if someone wrote an sql query to find all contacts for an account number in Oracle customer master. We are on EBS 11.5.10.
    I am also looking for sql query to find all ship to addresses for an account number.
    Thanks.

    Can you also post the query for people who read this post and are also looking for an answer?
    Regards,
    Johan Louwers.

  • Query to find all the suppliers who has their invoices on hold

    Hi All,
    Query to find all the suppliers who has their invoices on hold (at least 1) .
    Thanks,
    Vamshi

    Pls find the script to find the Hold invoies for those suppliers 
    select aps.VENDOR_NAME,aia.INVOICE_NUM,aia.INVOICE_AMOUNT
    from ap_suppliers aps,ap_invoices_all aia,ap_holds_all aha
    where aia.VENDOR_ID = aps.VENDOR_ID 
    and aia.INVOICE_ID = aha.INVOICE_ID 
    and aha.RELEASE_REASON is null
    Thanks
    Hari

  • Query to find all tasks on latest published version of a project

    Hello
    Can anybody help me on the query to find all tasks under latest published version of a project?
    Thanks!!

    Do you mean  "All tasks under latest published workplan version"??

  • Is there a query to find all software installed on a particular computer through the Add/Remove Programs?

    I am looking for a query to find all software on a specific computer. I have found several on a specific piece of software but I need multiple pieces of software. I have tried creating this query but it shows ALL the software on the computer. I'm looking
    for one that narrows it down to a few pieces of software i.e Office, Adobe, Snagit, IE and Chrome. Possibly using Add/Remove Software? 

    It's an asset intelligence report, do you have that enabled?
    http://technet.microsoft.com/en-us/library/gg699382.aspx
    Alternatively, take a look at the 'Products on a specific computer' report (Software - Companies and Products category) and see if that gets you what you need.
    Don't retire TechNet! -
    (Don't give up yet - 13,085+ strong and growing)

Maybe you are looking for