Query to get Primary and Foreing Key

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • luixleo
    New Member
    • Feb 2008
    • 2

    Query to get Primary and Foreing Key

    Hello .I need query in Oracle to get Foreing key and Primary key

    For Example
    I have two tables

    Category_Produc t
    Id_Category PK
    Description

    Product
    IdProduct PK
    Id_Category FK
    Description

    I need to get this

    Table ............... ...Column...... ........ TipyConstraint. ........Colum Ref Table _Ref

    Category_produc t......... Id_Category ............... PK
    Product........ ............... .. Id_Producto.... .......... Pk
    Product ............... ..........Id_Fa milia ............... FK ...... Id_Category.... .. Category_Produc t
  • debasisdas
    Recognized Expert Expert
    • Dec 2006
    • 8119

    #2
    Kindly post how u have attempted to solve this .

    Comment

    • subashsavji
      New Member
      • Jan 2008
      • 93

      #3
      Originally posted by luixleo
      Hello .I need query in Oracle to get Foreing key and Primary key

      For Example
      I have two tables

      Category_Produc t
      Id_Category PK
      Description

      Product
      IdProduct PK
      Id_Category FK
      Description

      I need to get this

      Table ............... ...Column...... ........ TipyConstraint. ........Colum Ref Table _Ref

      Category_produc t......... Id_Category ............... PK
      Product........ ............... .. Id_Producto.... .......... Pk
      Product ............... ..........Id_Fa milia ............... FK ...... Id_Category.... .. Category_Produc t
      some useful query

      select * from user_constraint s where table_name='EMP '; --Table name Capital
      //
      select * from user_cons_colum ns where table_name='EMP ';
      //

      Comment

      • debasisdas
        Recognized Expert Expert
        • Dec 2006
        • 8119

        #4
        try to use this

        [code=oracle]
        select t.table_name ,c.column_name, c.CONSTRAINT_NA ME,d.CONSTRAINT _TYPE from user_tables t,user_cons_col umns c,User_constrai nts d where t.table_name=c. table_name and t.table_name=d. table_name

        [/code]

        Comment

        Working...