Logical foreign key

Hi All,
I apologize to bring similar question. .
I am able to create the logical foreign key for logical table A with new joining condition (A.2=B.2) (2 is calculated logical column).
However there still exist Physical foreign key join with old condition (A1.=B.1). When I deploy this rpd, the report generates sql with (A1.=B.1) join condition.
Then,I removed this Physical foreign key join in rpd,and got a warning' logical dimension B has a source that does not join with any fact table' in consistency check.
Still after deploying this rpd , I am getting error [nQSError: 14025] No fact table exists at the requested level of detail: in report.
I am missing anything.The logical foreign key has correct join condition still it is not over riding the physical join.
Thanks for going through this question,
http://tinypic.com/r/2qiwmrr/6

Based on your comments I'm looking at documentation:
I found a Note: A logical key for a fact table must be made up of the key columns that join to the attribute tables. Logical foreign key joins may be needed if the Oracle BI Server is to be used as an ODBC data source for certain third-party query and reporting tools.
I need to see why ODBC, and unlike the Logical Foreign key join is not overriding join Physical layer.
Btw: Since you want to go with a join using defined logical column, can you use the same expression in Physical join using expression builder?
This should work.
EX: T43770.DEPARTMENT_ID = case when T43764.DEPARTMENT_ID > 10 then T43764.DEPARTMENT_ID else 0 end
Edited by: Srini VEERAVALLI on Jan 18, 2013 4:52 PM

Similar Messages

  • Logical foreign key display values

    I have a schema in which the primary keys are auto generated numbers. Foreign keys exist from child tables to the primary key of the parent.
    I have figured out how to change auto generated forms to display a dropdown list of display/values to the user on insert or update instead of the meaningless number.
    What I can't figure out how to do is have the generated report show the display that I am looking for without losing the ability to edit the child record. As soon as I manipulate the query to include another table I lose the icon in the application to edit the row.
    Is it possible to keep the edit icon on the report while showing logical values instead of actual ones?
    Thanks in advance,
    Chris S.

    We'll use a football analogy because it's time for the ployoffs.
    Let's create a TEAMS table and a DIVISIONS table.
    TEAMS consists of:
    TEAM_ID NUMBER -> PK
    LOCATION VARCHAR2(35)
    TEAM_NAME VARCHAR2(35)
    and DIVISIONS consists of:
    DIVISION_ID NUMBER -> PK
    DIV_NAME VARCHAR2(35)
    Now there can't just be a link from a team to a division because they move around a bit. The Detroit Lions used to be in the NFC Central. That doesn't exist anymore and now they are in the NFC North. (Please set aside the fact that the NFC should be a part of the conferences table).
    This means that I would create a table to link the TEAM record to a DIVISION record with the season that the team became a part of the division and potentially the last season that they were in that division. This table will be called DIVISION_TEAM_XREF and looks like this:
    LINK_ID NUMBER -> PK
    DIVISION_ID NUMBER -> FK(DIVISIONS.DIVISION_ID)
    TEAM_ID NUMBER -> FK(TEAMS.TEAM_ID)
    SEASON_EFF NUMBER(4) (actually a year maybe a VARCHAR2 would be better)
    SEASON_TERM NUMBER(4) (nullable)
    Now I created all of that through HTML DB with foreign keys from the XREF table to the teams and divisions tables. Then I create an application throught the application builder. I choose report and form and the application type like the demo. for each of the three tables. Choose a theme and walah there is an application with all three tables. If I add data to TEAMS or DIVISIONS I can see them in the report page that is created and there is an icon to the left of each row which when clicked will allow me to edit the row.
    The problem comes with my XREF table. The creation screen is just a form which expects me to know the auto generated number that was created for my division and team. I have figured out how to change this in the application builder so that it is a drop down list built from a query of the respective table.
    Once I create a record I can see it in the report page for the XREF table. This page has the option to edit the record but the values on the screen are the auto generated numbers that don't mean anything to a user. When I change this page to use display values from the parent tables I lose the edit icon.
    Here is the original query that the application builder used:
    select
    "LINK_ID",
    "DIVISION_ID",
    "TEAM_ID",
    "SEASON_EFF",
    "SEASON_TERM"
    from "DIVISION_TEAM_XREF"
    and here is what I would like to change it to:
    select
    XREF.LINK_ID "LINK_ID",
    DIV.DIV_NAME "DIVISION",
    TEAM.TEAM_NAME "TEAM",
    XREF.SEASON_EFF "SEASON_EFF",
    XREF.SEASON_TERM "SEASON_TERM"
    from "DIVISION_TEAM_XREF" XREF, DIVISIONS DIV, TEAMS TEAM
    where XREF.DIVISION_ID = DIV.DIVISION_ID
    and XREF.TEAM_ID = TEAM.TEAM_ID
    Sorry for the long post. Hope that clarifies.
    Chris S.

  • Foreign Keys for a Logical Table

    Hi All,
    I want to know in which scenarios we create the Foreign Keys for a Logical Table. Once we create the foreign key for the logical table, does it mean that it will automatically override if any joins are there.
    Physical Table A, B ( no physical joins)
    Logical Table A, B (logical join B(Dim)-->A(Fact))
    created the foreign key in logical table A with B .(A.1=B.1)
    Will the rpd generate sql with A.1=B.1 join condition for reports.
    I tried to create the logical foreign key for logical table A, I could not see any corresponding table option.Here is its snapshot
    http://tinypic.com/r/jq1gkz/6
    Thanks,
    Virat

    In general when we go complex joins in Physical layer we go for Logical foreign key joins in BMM layer, best examples is SCD Type-II.
    Physical Table A, B ( no physical joins)
    -->You need to have a physical join so that this can be override by BMM layer
    created the foreign key in logical table A with B .(A.1=B.1) Will the rpd generate sql with A.1=B.1 join condition for reports.
    -->Yes you can see this join in BI Physical query.
    I tried to create the logical foreign key for logical table A, I could not see any corresponding table option.Here is its snapshot
    -->2 cases: 1)You need to delete existing logical joins 2) You might not have join in physical layer.
    Hope this helps
    Let me know for issues
    Edited by: Srini VEERAVALLI on Jan 18, 2013 1:29 PM
    BTW: You got very good name, why dont you update in your profile to see your name instead of some number
    Edited by: Srini VEERAVALLI on Jan 18, 2013 1:29 PM

  • Foreign keys in logical fact

    Hi,
    Should I define foreign keys in logical fact table? I need to use "aggregation rule=count distinct" of the foreign key column in my reports.
    Thanks.
    Andy

    Hi Andy,
    You can add the foreign keys to your fact table as a measure column (count distinct aggregation).
    Do not use these foreign keys to create foreign key joins in the logical layer. Always use complex joins (http://obibb.wordpress.com/2010/08/06/joins-in-oracle-bi-ee/)
    Good Luck,
    Daan Bakboord
    http://obibb.wordpress.com

  • Data Modeler 3.0 EA1 - Logical Relation to Foreign Key not generating

    When use "Engineer to Relational Model" the only time it creates foreign keys from my relations is when those relations are of the type many-to-many. I've added a Primary UID for each table and I have tried to use the Apply Naming Standard options but nothing seems to work.
    I tested my design with the design rules feature I have no errors.
    Does anyone have any ideas?
    Greg

    Hi Greg,
    probably you added primary uid after first engineering to relational model. You can check whether those uids are selected in engineering dialog.
    Also you can check log file in datamodeler\datamodeler\log directory for logged problems there.
    Philip

  • Foreign Key Relationships to external associations - Is it really this dodgy or is there a better way?

    Hi All,
    Let's picture that I have a GW service called Search Helps and within that service I have a PersonalAreas Entity Set which acts as a search help for drop down fields effectively that need to select a Personal Area.  I have 3 properties, with Personal Area Id and Company Code being the keys, and the text for Personal Area being the 3rd and last property. You really need to filter PersonalAreas by Company Code otherwise it's a fairly useless result set.
    Now within a different GW service, I have an entity called Position which has a single key of PositionId.  There is also a a property of company code on this Position.
    Now rather than asking the UI developer to get the Company code value and filter PersonalAreas with it directly, I thought it would be nicer for the UI developer just to use the navigation from a specific Position to PossiblePersonalAreas.  e.g. Positions('123')/PossiblePersonalAreas returns the entity set of PersonalAreas filtered by the Position's Company Code.
    So with that in mind, I add the external model reference pointing at the search helps service; then create an external association via the sneaky External Associations Editor button (that doesn't appear on the Wizard just to confuse you), and set up my Dependent entity to point at the Search Helps PersonalAreas entity.
    At this point I really want to tie the Position's Company Code to the PersonalAreas Company Code, but all I can do is set up a referential constraint of PositionId to CompanyCode or have no referential constraint at all (note - in my example I added the referential constraint as there is an issue with navigation keys being provided to external associations from what I can tell - more about this below).
    So, without any other option, I go into my GetEntitySet method of PersonalAreas and write something like the following:
      CASE iv_source_name.
        WHEN 'Position'.
          READ TABLE it_filter_select_options ASSIGNING <filter> INDEX 1.
          CHECK sy-subrc = 0.
          READ TABLE <filter>-select_options assigning <select_option> INDEX 1.
          CHECK sy-subrc = 0.
          position_id = <select_option>-low.
    *     Get company code for position
          TRY.
              CREATE OBJECT o_position
                EXPORTING
                  i_position_id = position_id.
              o_position->get_cost_centre_information(
                IMPORTING
                  e_company_code = company_code
            CATCH zcx_hr_object.
          ENDTRY.
      endcase.
    * Continue with retrieving PersonalAreas for given Company Code
    <Remaining code not shown>
    e.g. I have to assume CompanyCode is actually "Position Id" when the source of this call is from Position (I could also look at the navigation to find this has come from Position but if you're wondering, unfortunately for external associations, the key is not included in this for some reason but the same followup logic of reloading the object would be required).
    So the question I'm hoping the answer to is Yes is: Am I missing something in my understanding here?
    Thanks,
    Matt
    Edit since posting and playing around a bit more: Thinking about this further - it's unfortunate, but the navigation property in odata really implies the dependent entity has knowledge of the principal entity and realistically must know how to instantiate it if it needs to get data based on one of the properties. 
    Now while I'm fine with that (sort of) I think it's wrong that the dependent entity needs to have the required key properties to hold the principal entities as it makes something like a generic search help impossible to do with navigation - Maybe I just need to be done with that and expect filters to be used by UI programmers to find foreign key'ed entities....

    Hi Matt,
    I'm not surprised that you have an issue with this. One bugbear I have with Gateway is that for some reason the designers don't think any context beyond the immediate preceding navigation node is important. They don't support this within the same service,so it's hardly likley to work in a service reference.
    I may be wrong but I don't think GW is OData compliant in this respect. If I have the navigation path /blindservice/FromHereSet(1)/ToAPoints(22)/ToBPoints, it's rather restrictive to say I cannot see the initial key of '1' in the path when I am trying to resolve 'ToBPoints'. If that value - where I started - is key to the context, I have to know it.
    Currently the only way to access this context is to embed the 'key history' in the intermediate entities, i.e. /blindservice/FromHereSet(1)/ToAPoints(1,22)/ToBPoints. In my view that is corrupting the URl to suit the limitations of the SAP OData implementation. What's even more confusing/frustrating is that the technical request context appears to be able to store the stacked navigation keys but doesn't make use of this design. 
    I feel your pain
    Ron.

  • Multiple foreign keys to a single table

    Hi,
    I need to write an SQL sentence to bring a unique row formed from multiple foreign keys which are dependent on the same table. The two tables as follow:
    CREATE TABLE UNIDADMEDIDA (
    IDUNIDADMEDIDA NUMERIC(3) NOT NULL,
    DESCRIPCION VARCHAR2(128) NOT NULL,
    CONSTRAINT PKUM PRIMARY KEY(IDUNIDADMEDIDA)
    CREATE TABLE TRANSPORTE (
    IDBOLETA NUMERIC(12) NOT NULL,
    CORRELAVEHICULO NUMERIC(2) NOT NULL,
    TIPOVEHICULO NUMERIC(1),
    TIPOGASOLINA NUMERIC(1),
    CANTIDAD NUMERIC(8),
    RECORRIDOPROMEDIO NUMERIC(10,2),
    IDUMRECORRIDO NUMERIC(3),
    CONSUMOPROMEDIO NUMERIC(10,2),
    IDUMCONSUMOPROM NUMERIC(3),
    CONSUMOTOTALANUAL NUMERIC(10,2),
    IDUMCONSUMOTOT NUMERIC(3),
    CONSTRAINT PKTRANSPORT PRIMARY KEY(IDBOLETA, CORRELAVEHICULO),
    CONSTRAINT FKUMRECORRI FOREIGN KEY(IDUMRECORRIDO) REFERENCES UNIDADMEDIDA(IDUNIDADMEDIDA),
    CONSTRAINT FKUMCONSUMO FOREIGN KEY(IDUMCONSUMOPROM) REFERENCES UNIDADMEDIDA(IDUNIDADMEDIDA),
    CONSTRAINT FKUMCONSTOT FOREIGN KEY(IDUMCONSUMOTOT) REFERENCES UNIDADMEDIDA(IDUNIDADMEDIDA)
    The columns IDUMRECORRIDO, IDUMCONSUMOPROM and IDUMCONSUMOTOT depend on the table UNIDADMEDIDA (specifically from the IDUNIDADMEDIDA field). I need to bring back the description (DESCRIPCION field) from the different values stored in TRANSPORTE table.
    Thanks for your help!!!
    Mario

    Welcome to the forum!
    Have you thought about joining against the parent table three times to pick up each different description?
    SELECT  <COLUMN LIST>
    ,       UNI_A.DESCRIPCION
    ,       UNI_B.DESCRIPCION
    ,       UNI_C.DESCRIPCION
    FROM    TRANSPORTE
    JOIN    UNIDADMEDIDA    UNI_A   ON UNI_A.IDUNIDADMEDIDA = TRANPORTE.IDUMRECORRIDO
    JOIN    UNIDADMEDIDA    UNI_B   ON UNI_B.IDUNIDADMEDIDA = TRANPORTE.IDUMCONSUMOPROM
    JOIN    UNIDADMEDIDA    UNI_C   ON UNI_C.IDUNIDADMEDIDA = TRANPORTE.IDUMCONSUMOTOT
    ;It is always helpful to provide the following:
    1. Oracle version (SELECT * FROM V$VERSION)
    2. Sample data in the form of CREATE / INSERT statements.
    3. Expected output
    4. Explanation of expected output (A.K.A. "business logic")
    5. Use \ tags for #2 and #3. See FAQ (Link on top right side) for details.
    You provided #2 partially. If you provide the rest we may be able to help you even further.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • SQL Developer Data Modeler - Relation to Foreign Key Generation

    SQL Developer Data Modeler 2.0.0 Build 584.
    I am having trouble with Relations to Foreign Keys when Forward Engineering a Relational Model from a Logical Model.
    First of all, the Naming Standard is not applied to the Foreign Keys when I perform the Engineer to Relational Model.
    So I right click on the Relational Model from the Browser and Apply Naming Standards to Keys and Constraints.
    I uncheck everything but Foreign Keys.
    Now, Foreign Keys are named according to my Naming Standards.
    However, this process also performs renames on the Column Foreign Keys even though I specifically unchecked that option.
    This appears to be a BUG in the software and I haven't found a way around it.
    I tried using {column} instead of {ref column} in the Naming Standard Template for Column Foreign Key, but that simply resulted in renaming my columns to "{column}".
    Please confirm and/or let me know of any work-around for this.
    Thanks,
    Dan

    Hi Philip,
    Thanks for the reply.
    Is this recorded as a bug to be addressed in the future?
    Should I submit this problem via Oracle Support?
    The other work-around I came up with is to override every Relation name in the Logical Model with the name I want to use in the Relational Model.
    When the Relational Model is Engineered, this becomes my Foreign Key name.
    Of course, this is not how I want to do things, so I am hoping for a bug fix someday.
    Regards,
    Dan

  • Basic doubt about Primary Key/Foreign Key in Oracle Tables

    Hi,
    I have a doubt whether Primary Keys/Foreign Keys are allowed in Oracle. Some of the people I know are telling me that Oracle does not encourage having Primary Keys/Foreign keys in its database tables.
    However if I go to the ETRM and look for information about some of the Oracle Tables, I am informed that Primary Keys do exist. However I am being told that ETRM is not a reliable way of having correct information about table structure.
    It would be great if any one of you provides me with some insight in this. Any pointers to a document would be great.
    Thanks

    It is not that PK/FKs are disallowed in Oracle Apps (there are some on the standard Oracle Apps tables), but they are typically not used. I am not positive what the logic behind this is, but my guess is that it was party due to the earlier versions of Oracle Apps pre-dating declarative database referential integrity in Oracle DB and also on performance issues with the standard referential integrity with the earlier versions of declarative database referential integrity.
    As far as eTRM is concerned - I understood that the data is based on a design repository rather than a physical Oracle Apps DB. So all of the information in there is logically correct, but not necessarily enforced via the standard Oracle DB declarative referential integrity (rather by the application code or APIs).

  • Composite foreign key issue

    Hi,
    I am trying to create a composite foriegn key. I have created my primary key as a composite key, made up of three fields.
    Table 1
    PatientID - Made from 3 fields(a,b,c)(primry key)
    Table B
    PatiendID- (should be the foreign key which references table1)
    However i am finding that when i try to create my constraint i get the following messages
    error 02270 - no matching unique or primarty key for this column list.
    below is the sample code i am using to create my foreign key)
    (ALTER TABLE XD_PatientSedation ADD CONSTRAINT fk_Sedation_PatientID FOREIGN KEY (PatientID)REFERENCES XD_Patient_Demographics(PatientID)
    I am really stuck on this and dont quite know what to do.
    Hope you can help.
    Thanks
    Jagdish

    Just speaking about design, when you want to use a foreign key, it already means that the referenced columns represent something important enough to be a primary key of some other table. I don't understand the business logic of your example (using real table and column names would help), but the solution is probably one of these two :
    a) your foreign key should in fact refer to (a,b,c), the complete primary key of the first table (what was suggested by the others).
    b) your foreign key should stay as 'a' (patientid?), you should have a third table (patients?) whose primary key is 'a', and your "Table 1" should have a foreign key on 'a', referencing the third table. In this case you may find it silly to create a new table with only one column, but I would bet that you will very soon think of interesting attributes which could be added to this table.
    In any case, I think that Oracle did a good job by forcing an improvement of your design !

  • Why do you expose the accessors of a foreign key association in an Entity?

    Hello Everyone:
    I am working on our re-usable Business Components .jar file. I am re-doing the one we had created in 10g from scratch in 11.1.2 in order to utilize all of the features of 11.1.2 and remove the problems we were having with re-factor in 10g.
    In 10g there was also a bug that gave us an error if we exposed the source and destination accessors of foreign keys if there were multiple similarly named source accessors for a number of foreign keys on a table. So we removed all the foreign key source and destination accessors. We only exposed the accessors for parent/child relationships and uniquely named them eg. Person_parent_to_PersonAddress. We have used a number of these parent/child accessors in customized coding logic, but not the foreign key accessors.
    Is anyone using the foreign key accessors and what function are you using them for? In moving forward with starting this re-usable Business Components .jar file, I am trying to determine if we should be exposing the foreign key source and destination accessors.
    Thanks in advance for any replies.
    Mary
    UofW

    Many thanks for the response. Don't think I can make use of synchronous replication with lookup tables given our own requirements.
    I was thinking however, by employing a hub-and-spoke replication model instead of an N-WAY, that this would avoid foreign key conflicts altogether.

  • How to apply Foreign Keys on top of a Common Lookup table

    I have an issue where i am mandated to enforce RI on an applications database (a good thing). but I have several common lookup tables where many of the "codes" reside for many different code types. I also have the mandate that i cannot change the
    underlying DDL to make composite keys to match the codes table PK. I am currently looking at creating indexed views on top of the Codes table to seperate the logical tables it contains. This is several hundred views. Although doable is there another solution
    I am not seeing? I have scoured the web in search of an answer knowing I cannot be the only SQL developer in this situation. I do know that I do not want to write several hundred triggers to enforce RI. Table schema below, the CdValue column is the column
    that is used throughout the hundreds of tables that use this codes table, and their corresponding column is not named the same.
    CREATE TABLE dbo.CodesTable (
    PartyGrpId INT  NOT NULL
      , CdTyp  VARCHAR ( 8 ) NOT NULL
      , CompId INT  NOT NULL
      , CdValue VARCHAR ( 8 ) NOT NULL
      , CdValueDesc VARCHAR ( 255 ) NULL
      , AltValueDesc VARCHAR ( 100 ) NULL
      , DefaultInd CHAR ( 1 ) NULL
      , OrderNum SMALLINT NULL
      , ActiveCd CHAR ( 1 ) NULL
      , ExpireDtm SMALLDATETIME NULL
      , EffectDtm SMALLDATETIME NULL
      , ModById INT  NULL
      , ModDtm SMALLDATETIME NULL
      , CreateById INT  NULL
      , CreateDtm SMALLDATETIME NULL
      , CONSTRAINT PC_dbo_EcdDetail
        PRIMARY KEY CLUSTERED ( PartyGrpId ASC, CdTyp ASC, CompId ASC, CdValue ASC )
        ON FG_Data
    ) ON FG_Data;
    I did though run into one forum where a person brought up a great idea. Filtered Foreign Keys, what a novel concept, if it could work it would make so much less code to fix an issue like this. :)
    ALTER TABLE dbo.BusinessStatus WITH NOCHECK
    ADD CONSTRAINT FK_dbo_BusinessStatus_CodesTable FOREIGN KEY (LoanStsDtCd) REFERENCES dbo.CodesTable (CdValue) WHERE CdTyp = 'Status'
    U.S. Army Airborne! The only way to fly

    >> I have several common lookup tables where many of the "codes" reside for many different code types. <<
    No! This is called “Automobiles, S quids and Lady Gaga” SQL and laugh at you or fire you or both. A table is a set; a set has one and only one kind of element it it. This is the basis of RDBMS and First Normal Form. 
    This is so bad it has a name; OTLT for “One True Lookup Table” ;I give an example of how stupid this in one of my books where a Dewey Decimal Classification for Churches is the same as the ICD code for deformed testicles. 
    There is no such crap as a “generic_type_code” in RDBMS. It either a “<something in particular>_type” or a “<something in particular>_code” in data modeling and the ISO-11179 standards.
    You have more NULL-able columns in one table than you should have in an entire schema! 
    You have audit data (creation and modification) in the row under audit. This is both stupid and illegal. You cannot expose the audit trail to the data user by law. When you delete a row, you also destroy the audit trail –Doh! 
    You have no CHECK() constraint on the (effective_date, expiry_date) pair. 
    Putting “_table” in a table name is a design error called a “tibble” to make fun of how silly it. You might want to download the PDF of bad SQL code smells from Red Gate so you can avoid things like this. 
    >>  the CdValue column is the column that is used throughout the hundreds of tables that use this codes table, and their corresponding column is not named the same. <<
    “_value” and “_code” are both what ISO-1179 calls an attribute property. It is a silly as a list of adjectives without a noun. 
    Each encoding is a separate table in a valid schema, each with its own validation and verification. You have to stop doing this. This is fundamental!! 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Database diagram not displaying foreign keys

    I've created a database diagram by importing tables from a database, and then manually creating the Foreign Keys on the diagram ( they're logical FKs, but not actually on the database ).
    Now, when I reopen the diagram, the 'Structure' tab in the bottom LHS initially displays a list of all of the FKs and tables, and then the list shrinks to just 3 of the 15 or so FKs ( plus the tables ), and only these 3 are displayed on the diagram!
    I can post the diagram file if someone wants to go through it and find out the problem.
    The diagram was created in 10.1.3.1, and will not open correctly in either 10.1.3.1 or SU4.
    *

    Liam,
    Can you zip me up you project so that I can take a look?
    Can you rename the zip file extension to '.zap' to get it through the mail server.
    My email address is [email protected]
    Regards,
    Lisa
    JDev QA

  • Using FOreign key constraints on tables in database.

    I am student and novice in the field of ORACLE and PL/SQL and Database Creation. I had created a database consisting tables and got problem while applying foreign key constraints.
    CUST_MSTR
    CREATE TABLE "DBA_BANKSYS"."CUST_MSTR"("CUST_NO" VARCHAR2(10),
    "FNAME" VARCHAR2(25), "MNAME" VARCHAR2(25), "LNAME" VARCHAR2(25),
    "DOB_INC" DATE NOT NULL,      "OCCUP" VARCHAR2(25), "PHOTOGRAPH" VARCHAR2(25),
    "SIGNATURE" VARCHAR2(25), "PANCOPY" VARCHAR2(1),      "FORM60" VARCHAR2(1));
    (CUST_NO is PRIMARY KEY, )
    -- EMP_MSTR
    CREATE TABLE "DBA_BANKSYS"."EMP_MSTR"("EMP_NO" VARCHAR2(10),
    "BRANCH_NO" VARCHAR2(10), "FNAME" VARCHAR2(25), "MNAME" VARCHAR2(25),
    "LNAME" VARCHAR2(25), "DEPT" VARCHAR2(30), "DESIG" VARCHAR2(30));
    (EMP_NO is primary key )
    --NOMINEE_MSTR
    CREATE TABLE "DBA_BANKSYS"."NOMINEE_MSTR"("NOMINEE_NO" VARCHAR2(10),
    "ACCT_FD_NO" VARCHAR2(10), "NAME" VARCHAR2(75), "DOB" DATE,
    RELATIONSHIP" VARCHAR2(25));
    (NOMINEE_NO is primary key )
    --ADDR_DTLS
    CREATE TABLE "DBA_BANKSYS"."ADDR_DTLS"("ADDR_NO" NUMBER(6),
    "CODE_NO" VARCHAR2(10),      "ADDR_TYPE" VARCHAR2(1), "ADDR1" VARCHAR2(50),
    "ADDR2" VARCHAR2(50), "CITY" VARCHAR2(25), "STATE" VARCHAR2(25),
    "PINCODE" VARCHAR2(6));
    ( ADDR_NO is primary key )
    Problem: I want to apply foreign key constraints on ADDR_DTLS table so that Before inserting value in ADDR_DTLS table it must check, VALUE in ADDR_DTLS.CODE_NO must be PRESENT either in attribute value CUST_MSTR.CODE_NO or EMP_MSTR.CODE_NO or NOMINEE_MSTR.CODE_NO table .
    I applied the foreign key constraints using this syntax
    CREATE TABLE "DBA_BANKSYS"."ADDR_DTLS"("ADDR_NO" NUMBER(6),
    "CODE_NO" VARCHAR2(10),      "ADDR_TYPE" VARCHAR2(1), "ADDR1" VARCHAR2(50),
    "ADDR2" VARCHAR2(50), "CITY" VARCHAR2(25), "STATE" VARCHAR2(25),
    "PINCODE" VARCHAR2(6),
    constraints fk_add foreign key CODE_NO references CUST_MSTR. CODE_NO,
    constraints fk_add1 foreign key CODE_NO references EMP_MSTR. CODE_NO,
    constraints fk_add2 foreign key CODE_NO references NOMINEE_MSTR.CODE_NO);
    (foreign key)
    ADDR_DTLS.CODE_NO ->CUST_MSTR.CUST_NO
    ADDR_DTLS.CODE_NO ->NOMINEE_MSTR.NOMINEE_NO
    ADDR_DTLS.CODE_NO ->BRANCH_MSTR.BRANCH_NO
    ADDR_DTLS.CODE_NO ->EMP_MSTR.EMP_NO
    When I applied foreign key constraints this way, its gives a error called foreign key constraints violation. (I understand that, its searches the attribute value of ADDR_DTLS.CODE_NO in all the three tables must be present then the value will be inserted. But I want, if the value is in any of the three table then its should insert the value or its gives an error.)
    Please help me out, though i put the question and i want too know how to apply the forign key in this way. and is there any other option if foreign key implementation is not pssible.

    If you are on 11g you can use ON DELETE SET NULL:
    CREATE TABLE addr_dtls
    ( addr_no          NUMBER(6)  CONSTRAINT addr_pk PRIMARY KEY
    , addr_cust_no     CONSTRAINT addr_cust_fk    REFERENCES cust_mstr    ON DELETE SET NULL
    , addr_emp_no      CONSTRAINT addr_emp_fk     REFERENCES emp_mstr     ON DELETE SET NULL
    , addr_nominee_no  CONSTRAINT addr_nominee_fk REFERENCES nominee_mstr ON DELETE SET NULL
    , addr_type        VARCHAR2(1)
    , addr1            VARCHAR2(50)
    , addr2            VARCHAR2(50)
    , city             VARCHAR2(25)
    , state            VARCHAR2(25)
    , pincode          VARCHAR2(6) );In earlier versions you'll need to code some application logic to do something similar when a parent row is deleted, as otherwise the only options are to delete the dependent rows or raise an error.
    btw table names can be up to 30 characters and don't need to end with MSTR or DTLS, so for example CUSTOMERS and ADDRESSES might be more readable than CUST_MSTR and ADDR_DTLS. Also if the Customer/Employee/Nominee PKs are generated from a sequence they should be numeric.
    Edited by: William Robertson on Aug 15, 2010 6:47 PM

  • [JPA] Primary key = Foreign key = Failure.

    Hello:
    I've a question regarding the Java Persistence API and a DB design which I'm facing just now. I'm making JPA entities based on a DB schema which is already created. Although sometimes it's not a good idea, I'm going to use a simplified example so you can understand it easily and help me (if you want, of course).
    Let's suppose that I've a table of discs (called "disc", built into a class as "Disc.class") and another one of used discs (called "disc_used", built as "DiscUsed.class"). The first one employs a composite key formed by columns "key1" and "key2". The second one employs the same primary key (conceptually, not physically) which, at the same time, is foreign key respect to the first table.
    I've used the @EmbeddedId annotation on the first case and built a class for the composite key (called "DiscPK.class"). I've done the same task for the second table (calling it "DiscUsedPK.class"). I also have added the corresponding mappings between both classes (of type @OneToOne). This design pattern works fine when employing "Disc.class", but not "DiscUsed.class". I've came to the conclusion that it's because of using the same fields to make an @EmbeddedId and map the @OneToOne relation.
    I've been taking a deep look to the possible annotations which JPA offers, but I've not found anything useful.
    In the past I faced another problem with JPA and composite keys, which made me come to the conclusion that it was my DB design what was faulty (I was combining an auto-numerical field with others to make a composite key, which helped me to understand the logic but was absurd and against the relational logic). May it be a similar misconception on the DB design? I mean, since both tables represent different concepts (discs and used discs), each one with their own attributes (columns), Should the second table use its own auto-numerical primary key instead of re-use the foreign key? Would it be the right approach according to the relational logic?
    Obviously, modifying the original DB by hand and adding its own primary key, it works flawless. However I still need to know the truth (other-way I won't be able to sleep :P ).
    Thank you for your help and interest.

    gimbal2: I'm really sorry, but I didn't get any e-mail notification about your message :S . After having looked for help on several places on the Internet I finally decided not to employ exactly the same columns for a primary key if they were already being employed by a foreign key. The answer from javaUserMuser has also left this matter clarified to me. Thanks for your time also ;) .
    javaUserMuser: I thought that was a problem from my implementation. If it's a common case, then I guess that I did right choosing the easy "path" for one time :) . I agree with you, it's a big frustration. But since I depend on the JPA for my projects, I'll try to set my mind to avoid always this match and employ another primary key instead. Thank you a lot for your explanation :D .

Maybe you are looking for

  • Slow System

    For no apparent reason, my Mac desktop has started running slow. Slow response to everything. Of course, I am spoiled and am used to blazing speed. Is there anything I can do to clean things up a little? Nothing has changed on the machine to speak of

  • Problem in VA02 call transaction

    Hi Friends I processed failured IDOC through ZPROGRAM, after processing IDOC it will create a sale order and display the order number in my program output.Whenever user clicks that button it should take him into VA03 transaction.It was working fine,

  • Why Does the iPhone not send/receive MMS?

    Why Does the iPhone not send/receive MMS? this in the works?

  • Can I get movie to fade to black?

    I inserted a Youtube video into my project and used the slider in Widget, Interaction to stop it about midway through, the first part being all that I wanted to show. But then when I preview it, it simply stops abruptly and retains the last screen im

  • MfE: "Maximum number of mailboxes defined" error

    I have had to wipe/reset and reinstall my E72. I have recreated my POP and Hotmail messaging accounts OK using Nokia EMail (www.email.nokia.com), but when I try to create my company Exchange account I get the error message "Maximum number of mailboxe