To check the foreign keys

i need to know the table which gives a mapping of foreign keys...that is the key name its own table and then the table to which it is mapped as a foreign key

Hi 477390,
Here is the query.
col "Primary Table" forma a30
col "Primary Key constraint" forma a30
col "Child Table" forma a30
col "Reference Key constraint" forma a30
select a.table_name "Primary Table"
     ,a.constraint_name "Primary Key constraint"
     ,b.table_name "Child Table"
     ,b.constraint_name "Reference Key constraint"
from      dba_constraints a
     ,dba_constraints b
where a.constraint_name=b.r_constraint_name
and a.owner='<SCHEMA_NAME>';
Cheers,
Kamalesh JK

Similar Messages

  • I am unable to create the Foreign key

    Hi,
    I need to create the Foreign key which reffered to composite primary key.
    the following table structure
    Parent table
    DIVISION, PROJECT_NUMBER, COMPETITION_PROJECT_NUMBER, COMPETITIVE_STMT_TYPE, SEQUENCE, CATEGORY, STATEMENT, USER_ID, RECORD_MODIFICATION_DATE
    Here composite primary key columns(DIVISION, PROJECT_NUMBER, COMPETITION_PROJECT_NUMBER, COMPETITIVE_STMT_TYPE, SEQUENCE)
    Child Table
    DIVISION          VARCHAR2 (4)          
    PROJECT_NUMBER          NUMBER (10)COMPETITION_PROJECT_NUMBER     NUMBER (10)          
    COMPETITIVE_STMT_TYPE          VARCHAR2 (2)          
    SEQUENCE     NUMBER (2)          
    CATEGORY          VARCHAR2 (100)     
    STATEMENT     LONG          
    USER_ID     VARCHAR2 (100)          
    RECORD_MODIFICATION_DATE     DATE     
    ALTER TABLE COMPETITION_STMT ADD (CONSTRAINT COMPET_STMT_FK_PROJ_NUM foreign key
              (PROJECT_NUMBER) REFERENCES PROD_COMPET_XREF (PROJECT_NUMBER));
    when i am trying to create foreign key i got this error
    ORA-02270: no matching unique or primary key for this column-list
    this is production issue Please help me.
    Thanks in advance
    Regards
    Kumar.s

    ALTER TABLE PROD_COMPET_XREF ADD (
    CONSTRAINT PROD_COMP_XREF_PK_DPNCPNCT
    PRIMARY KEY
    (COMPETITION_PROJECT_NUMBER, PROJECT_NUMBER, DIVISION, PRODUCT_LOC_INDICATOR)
    When you create a foreign key, it must reference a unique or primary key. The primary or Unique key must consist ONLY of those columns upon which the Primary key is based.
    You must Alter the table and add a Unique key if you want to keep your compsite primary key constraint. The Unique key must be for only the column that your foreign key references. Then try to recreate your foreign key.
    I doubt you will be able to add a foreign key because I suspect you might have multiple rows with the same value for this column based on your composite key; however, if you only intend for the project number to be listed only once and to be unique for each row, then the unique key may work or you may want to revist your primary key on this table. Perhaps you don't need it to be a composite PK???
    If you can't work around that, one thing you can do is build a table based just on PROJECT_NUMBER that contains details about the project number and have other tables reference that. That is, if you have multiple rows with the same project number in that table. You may already have one? Perhaps you can build your foreign key to reference that?

  • Disable all the foreign keys in a database

    Hy, what sql to use to disable all the foreign keys in a database and how to enable all them again. Thanks

    select * from dba_constraints where constraint_type = 'R' and status = 'ENABLED'
    ALTER TABLE table_name
    disable CONSTRAINT constraint_name;
    ALTER TABLE table_name
    enable CONSTRAINT constraint_name;
    select
    'ALTER TABLE ' || OWNER || '.' || table_name || ' enable CONSTRAINT ' || constraint_name || ';'
    from dba_constraints where constraint_type = 'R' and status = 'ENABLED';
    Execute and save result for enable before disable
    select
    'ALTER TABLE ' || OWNER || '.' || table_name || ' disable CONSTRAINT ' || constraint_name || ';'
    from dba_constraints where constraint_type = 'R' and status = 'ENABLED';
    Execute result for disable.

  • How to retrieve the Foreign key information in Oracle

    I want to know how to retrieve the Foreign Key information in Oracle while using SQL Statement?
    I have use three SQL statement to retrieve such information, but the performance is very bad.
    The three SQL Statements are:
    Select constraint_name, r_constraint_name from all_constraints where constraint_type = 'R' and table_name = table1;
    Select column_name from all_cons_columns where constraint_name = cons1;
    Select table_name, column_name from all_cons_columns where constraint_name = r_ccons1;
    Do anyone know another method to retrieve the Foreign Key information which has better performance?

    These sql-statements don't seem very performance intensive. My guess is something is wrong with your database (unless you have millions of constraints). How many constraints do you have? how many concurrent users? What is your dictionary cach hitratio? (other hitratio?) memory problems? other tasks of the computer? is this query the only one being slow? etc.

  • Problem to insert id into the foreign key  php/mysql

    Hello all,
    I'm having rouble to understand the process and there is no tutorial about my problem anywhere
    I have two table:
    Table 1 (member) with id, name, phone etc
    Table2 (post) add_id, title, description, price, member_id
    I got a form to post the add and I need to insert the id of table 1 into my table 2 member_id zone
    Fisrt I did the recorset to get user id
    $colname_rsMember = "-1";
    if (isset($_SESSION['MM_Username'])) {
      $colname_rsMember = $_SESSION['MM_Username'];
    mysql_select_db($database_connect, $connect);
    $query_rsMember = sprintf("SELECT * FROM member WHERE username='".$_SESSION['MM_Username']."'")or die(mysql_error());
    $rsMember = mysql_query($query_rsMember, $connect) or die(mysql_error());
    $row_rsMember = mysql_fetch_assoc($rsMember);
    $totalRows_rsMember = mysql_num_rows($rsMember);
    This part is working and I'm able to retreive info via echo just for testing
    After this code I have my insert code
    if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {
      $insertSQL = sprintf("INSERT INTO add (title, `description`, price, member_id) VALUES (%s, %s, %s, %s)",
                           GetSQLValueString($_POST['title'], "text"),
                           GetSQLValueString($_POST['description'], "text"),
                           GetSQLValueString($_POST['price'], "text"),
                           GetSQLValueString($_POST['member_id'], "int"));
      mysql_select_db($database_connect, $connect);
      $Result1 = mysql_query($insertSQL, $connect) or die(mysql_error());
      $insertGoTo = "ok.php";
      if (isset($_SERVER['QUERY_STRING'])) {
        $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
        $insertGoTo .= $_SERVER['QUERY_STRING'];
      header(sprintf("Location: %s", $insertGoTo));
    Do I need to include hidden field in y form?
    I'm having the same error message. Col member_id can't not be null
    Any idea what I'm doing wrong?
    Thank You!

    When someone logs in, Dreamweaver creates a session variable called $_SESSION['MM_Username']. Use that session variable to create a recordset to get the user's ID, which can then be entered into the foreign key field of the child table.
    Dreamweaver automatically puts the code for recordsets immediately above the DOCTYPE declaration, so you will need to move it above the code for the Insert Record server behavior. So, it needs to be in this order:
    Recordset to get user ID
    Insert Record for child table

  • SSAS 2008 Linking two cubes on the foreign key between two fact tables

    Hi, all -- 
    I have two cubes:
    Cube 1 has Fact1 (F1, "Events") and 3 dimensions (D1, D2, D3)
    Cube 2 has Fact2 (F2, "Sales") and 3 dimensions (D4, D1, D6)
    As you can see, two cubes reuse D1 as their common dimension.  In addition, F2 foreign keys into F1, e.g. F1 is "Events", and F2 is "Sales".  Every "sale" is an "event", but not every "event" is
    a "sale".
    The question is, how to I link the two cubes and their two respective fact tables on the foreign key?
    Thanks, Austin.

    Hi Austin,
    According to your description, you want to retrieve data from two different cubes, right? In Analysis Services, to query multiple cubes from a single MDX statement you can use the LOOKUPCUBE function (you can't specify multiple cubes in your FROM statement).
    The LOOKUPCUBE function will only work on cubes that utilize the same source database as the cube on which the MDX statement is running. For the detail information about it, please refer to the link below to see the blog.
    Retrieving Data From Multiple Cubes in an MDX Query Using the Lookupcube Function
    If I have anything misunderstood, please point it out.
    Regards,
    Charlie Liao
    TechNet Community Support

  • Populate the foreign key automatically

    HI All!
    I have a form in which there are two data blocks One is emp_master and other is salary_details.I have a foreign key salary_code in Emp_master and similarly Salary_code as primary key in salary details.I have used two list item in place of Emp_id and Salary_code.I want that when I select the emp_id as 10 from the list automatically salary_code list item should get populated by 1 item in the list item.Similary the rest should follow .Please someone look into this matter it would be a gr8t help to me.
    Thanks

    Abha,
    I would not use list items for this. Instead, use a multi-record text box with a scroll bar. It looks and behaves like a t-list, but is much easier to code and manage.
    Use the datablock wizard to create the master-detail relationship. When you use the wizard, all the code will be generated for you. Then use the layout wizard, and display multiple records with scroll bars.
    BTW, it is customary to have the primary key in the master, and the foreign key in the details. In your case it is backwards.
    Also see
    http://www.oracle.com/technology/obe/obe_as_10g/bi/forms/formsmasterdetailobe.htm

  • HOWTO: get JDev to show the foreign keys in Conn Nav & struct window

    Hi,
    I have SQL tables with foreign keys but the JDev connections navigator and table editor dont show them. They just look like primary keys in the "PK" column. The structure window shows a bunch of constraints with names like "SYS_C00143114" which is not very meaningful to me. Surely JDeveloper knows what these magic numbers mean and can trace the foreign keys for me.
    How can I get JDeveloper to show the foreign keys, and which table is referenced by that foreign key? Can I make it navigate from a table's foreign key value to the the correct tuple in the referenced table?
    Maybe this is an ER if JDev doesn't do this already. Navigating a schema, or drawing it showing all the foreign key references would be very handy. Navigating through actual table data would be nice too.
    Cheers,
    Simon.

    I found "new->Database Diagram" that does a lot of what I wanted, at least in mapping out the foreign key references. Now if I can just figure out how to print a .png file...
    It would still be nice for the connection navigator to trace them also.

  • Where the foreign key constraint is being physical store? Which tablespace?

    Hi,
    anyone got any idea where the foreign key constraint is being physical store? Which tablespace?
    Thank You...

    A foreign key constraint itself is purely logical -- there is no storage associated with it other than it's definition being stored in the data dictionary tables. If there is an index on the referencing column(s) then you can see where it is stored from the user_indexes view, although strictly speaking it's not part of the FK itself.

  • Identifying the Foreign Keys

    How can I identify the Foreign Keys in a row ???
    Regards,
    Junior

    How can I identify the Foreign Keys in a row ???Junior:
    Are you referring to FKs of a View Row involved in a View Link? If so, a View Row could have multiple FKs if it is involved in multiple View Links.
    By writing MT (middle-tier) code, you can get the attribute list from the View Link. Note that this logic is only available in MT. If you need this info in the client, you can write this logic in MT and export it as a custom method that can be called from client.
          // Get the list of view links that this VO ('vo')
          // is involved in.
          String[] vls = vo.getViewLinkNames();
          // Get the View Link object.
          ViewLink vl = myAM.findViewLink(vls[0]);
          // Get the View Link definition.
          oracle.jbo.server.AssociationDefBase vlDef = (oracle.jbo.server.AssociationDefBase)
               ((oracle.jbo.server.ViewLinkImpl) vl).getDef();
          AttributeDef[] attrs;
          // Get the source side attribute definitions
          attrs = vlDef.getAttributeDefImpls();
          for (int j = 0; j < attrs.length; j++)
             System.out.println("  Attr: " + attrs[j].getName());
          // Get the destination side attribute definitions
          attrs = vlDef.getOtherAttributeDefImpls();
          for (int j = 0; j < attrs.length; j++)
             System.out.println("  Attr: " + attrs[j].getName());

  • How to update the foreign key in a 1-to-many relation ?

    I have Product mapped to Channel as 1-1, and Channel mapped to Product as 1-M. Product has a nullable channel_id_fk as a foreign key to Channel, (so one can optionally specify or change the channel of a specific product).
    Starting with a specific product with a null channel_id_fk, I
    1) add this product to a channel (with a vector of products via ValueHolderInterface);
    2) set the channel of this product; and
    3) update the channel in a unit-of-work.
    The product.channel_id_fk doesn't get updated in db.
    I tried setting each side of the relation as read-only, but still it doesn't work.
    What am I missing ?
    (I am using toplink 9.0.4)

    More info:
    1) There is only a single uow involved, so there is no nested transaction.
    2) I tried checking the "target foriegn key" in the 1-1 mapping from Product to Channel, but this resulted in a exception thrown during runtime when the channel is accessed from the product:
    Local Exception Stack:
    Exception [TOPLINK-6094] (OracleAS TopLink - 10g (9.0.4) (Build 031126)): oracle.toplink.exceptions.QueryException
    Exception Description: The parameter name [AFFINITY_CHANNEL_ID_FK] in the query's selection criteria does not match any parameter name defined in the query.
    Query: ReadObjectQuery(au.com.agl.application.scorecard.AffinityChannel)
         at oracle.toplink.exceptions.QueryException.parameterNameMismatch(QueryException.java:658)
         at oracle.toplink.internal.expressions.ParameterExpression.getValue(ParameterExpression.java:149)
         at oracle.toplink.queryframework.SQLCall.translate(SQLCall.java:334)
         at oracle.toplink.internal.queryframework.CallQueryMechanism.executeCall(CallQueryMechanism.java:129)
         at oracle.toplink.internal.queryframework.CallQueryMechanism.executeCall(CallQueryMechanism.java:111)
         at oracle.toplink.internal.queryframework.CallQueryMechanism.selectOneRow(CallQueryMechanism.java:584)
         at oracle.toplink.internal.queryframework.ExpressionQueryMechanism.selectOneRowFromTable(ExpressionQueryMechanism.java:792)
         at oracle.toplink.internal.queryframework.ExpressionQueryMechanism.selectOneRow(ExpressionQueryMechanism.java:763)
         at oracle.toplink.queryframework.ReadObjectQuery.execute(ReadObjectQuery.java:340)
         at oracle.toplink.queryframework.DatabaseQuery.execute(DatabaseQuery.java:498)
         at oracle.toplink.queryframework.ReadQuery.execute(ReadQuery.java:111)
         at oracle.toplink.publicinterface.Session.internalExecuteQuery(Session.java:1968)
         at oracle.toplink.threetier.ServerSession.internalExecuteQuery(ServerSession.java:629)
         at oracle.toplink.publicinterface.Session.executeQuery(Session.java:1096)
         at oracle.toplink.internal.indirection.QueryBasedValueHolder.instantiate(QueryBasedValueHolder.java:52)
         at oracle.toplink.internal.indirection.DatabaseValueHolder.getValue(DatabaseValueHolder.java:63)
         at au.com.agl.application.scorecard.ProductDetails.getExclusiveAffinityChannel(ProductDetails.java:69)
    ....

  • Check constraint/foreign key combination

    I would like to add a constraint (check, FK, or otherwise) that forces a value to be either -1 OR be in a foreign table.  The statement below is invalid because you can't use subqueries, but I think it's clear what I'm trying to do.  Can anyone
    suggest a different approach?
    Thanks!
    ALTER TABLE cfg.ClientFieldThreshold ADD CONSTRAINT CK_cfg_ClientFieldThreshold_DBListID
    CHECK (DBListID = -1 OR DBListID IN (SELECT ID FROM dbo.vwClientDatabases)
    /* the subquery here isn't allowed */

    3 ways to do this. 
    1) use NULL instead of -1 as the value that does not have to be in the foreign table.  Then you just need a normal foreign key (because a foreign key column that contains NULL is not checked against the foreign table.  Sample code to do this
    Create Table FooParent(ParentID int primary key);
    Create Table FooChild(ChildId int primary key, ParentID int Null, Constraint FooChildFK Foreign Key(ParentID) References FooParent);
    go
    -- Can add row with NULL
    Insert FooChild(ChildId, ParentID) Values (1, Null);
    go
    -- But cannot add row with any other value that is not in FooParent
    Insert FooChild(ChildId, ParentID) Values (2, 25);
    go
    -- Check result
    Select * From FooChild;
    go
    Drop Table FooChild;
    go
    Drop Table FooParent;
    2) Add a dummy row to the parent table with a primary key of -1.  Then, of course, all you need is a foreign key constraint.
    3) Add a persisted computed column that is NULL whenever your column that you want to enforce the constraint against is equal to -1, otherwise just the value in that column.  Then create a foreign key on the computed column.  Sample code
    Create Table FooParent(ParentID int primary key);
    Create Table FooChild(ChildId int primary key, ParentID int Not Null, AlteredParentID As NULLIF(ParentID, -1) Persisted, Constraint FooChildFK Foreign Key(AlteredParentID) References FooParent);
    go
    -- Can add row with -1
    Insert FooChild(ChildId, ParentID) Values (1, -1);
    go
    -- But cannot add row with any other value that is not in FooParent
    Insert FooChild(ChildId, ParentID) Values (2, 25);
    go
    -- Check result
    Select * From FooChild;
    go
    Drop Table FooChild;
    go
    Drop Table FooParent;
    Tom

  • Quality Check view foreign key

    Headstart Ruleframe Designer6i
    Running utility quality check view definition
    Report states that complete property for _CG foreign key must be set to "NO" to keep from being generated in DB. However if foreign key is used in formmodule error CDG-3436 is raised : " Invalid Linkage ". I'm I correct in assuming that Complete property has to be set to "YES" and Validation property to "CLIENT" to avoid the errors?

    You are correct. I will log this as a bug in the quality check report.
    Thanks,
    Lauri

  • How to customize the foreign key constraint exception

    Hi All,
    I have two table, A and B.
    B.ref is foreign key references to A.id in database.
    Now I want to delete a row of table A in screen, error messages are :
    "Constraint "xxx.xxxx_S_FK1" is violated during post operation "Delete" using SQL statement "DELETE FROM xxxxxx WHERE xxxxxxxxx" and "ORA-02292: integrity constraint (xxx.xxxx_S_FK1) violated - child record found"
    How do I customize this error message? Is it possible to do it in EO Validation?
    Thank you!

    You can override the DoDML() method in EntityImpl something like follows
    @Override
    protected void doDML(int i, TransactionEvent transactionEvent) {
    try
    super.doDML(i, transactionEvent);
    catch(DMLConstraintException _ex) {
    if(_ex.getErrorCode().equals("26048") ) {
    // handle your exception
    sid

  • Bapi incoming invoice not checking the tolerance keys

    Hi,
       I  am using bapi BAPI_INCOMINGINVOICE_CREATE to post an invoice.Does it cover the tolerance check.
    If it doesnt check all the tolerance keys  lthen is there any other function module which can be used?
    Any one ??Plz help.

    Hi,
    put a break-point in these fm´s:
    FI_TOLERANCES_CHECK
    MRM_TOLERANCE_CHECK
    and execute the bapi.
    Best regards.

Maybe you are looking for

  • Since new iTunes version, iPhone is no longer scyncing with Outlook. Any help?

    No problem wiht previous iTunes version.

  • Issue while creating Purchase order (ME21N)

    Hi Friends, Hope U Have a Good Day... My issue is while creating purchase order , I enter vendor and in org.data tab I enter Pur.Org,company code and purchase group. After entering these values if I check in communication tab, the sales person and te

  • Facebook apps on Playbook cant logged in

    "An unexpected error has occured" appears when I try to log in into facebook  thru facebook apps on Playbook ,can anyone could help me some solutions,being appreciated and thanks in advance

  • Easy way to delete registers

    Hi, HI have one dbtable ( field1, kont ) and I want to delete the registers that the vkont is in the internal table itab2(vkont). I try something like : delete ZBKPF where HKONT NOT IN (select vkont from itab2). But it doesnt work. Any easy idea to d

  • Web Applet Problem OnDemandRdrtLogin Iframe

    Hi, we have multiple Web Applets attached to one object. The Administrator has no problem. We see all the Web Applet with the correct results. But if we login into the system with the standard user the first time we see the following link in each web