Foreign Key reference

Hi all,
I have two tables called PATIENT and PERSON. All persons are not patients but all patients are persons. Now how to define the relation between the two tables? Should PATIENT have foreign key reference to PERSON or should PERSON have foreign key reference to PATIENT?
thanks in advance.

It really depends what you want to accomplish. If 99% of people are patients, then it may be better to merge these two tables into one. If just a few people are patients, that a separate patient table is o.k. with the same key as in person table.

Similar Messages

  • Two foreign keys reference on primary key

    There are two tables:
    1) table CALENDAR with primary key: cal_id
    2) table FACTS with some columns, two of them are dates: cal_id_start_process, cal_id_stop_process
    we want on physical layer create two foreign keys for cal_id_start_process and cal_id_stop_process columns reference on CALENDAR.cal_id
    When we create foreign key for cal_id_start_process: we choose this column and choose CALENDAR table and its primary key. But when we want to create foreign key for cal_id_stop_process - we cannot coose table CALENDAR again.
    Is this rigth, that only one column from table can reference on specified primary key in CALENDAR table?
    How to create two foreign key on one table primary key?

    More complex. In your example there'll be such SQL:
    select c.cal_id, f.cal_id_start, f.cal_id_stop
    from CALENDAR c, FACTS f
    where c.cal_id = f.cal_id_start and c.cal_id = f.cal_id_stop
    (It meens FACTS.cal_id_start = FACTS.cal_id_stop )
    In my case, I want for such join:
    select c1.cal_id, c2.cal_id, f.cal_id_start, f.cal_id_stop
    from CALENDAR c1, CALENDAR c2, FACTS f
    where c1.cal_id = f.cal_id_start and c2.cal_id = f.cal_id_stop
    Edited by: annylut on Dec 22, 2011 3:33 PM

  • Hibernate: how to null out foreign key references when deleting an entity?

    We use Spring/Hibernate3 in our app, and ran into kind of a bummer of a problem. We have a relationship that is many-to-one (e.g. Student -> School). This is represented by a schoolId on the Student table. When we delete the school through the Hibernate layer, we are immediately receiving foreign key constraints because Hibernate does not null out the Students' schoolId columns where applicable.
    What we'd like to see happen is something like this:
    1. SchoolDAO.delete(id)
    Hibernate: UPDATE Student set schoolId = NULL where schoolId = ?
    Hibernate: DELETE from School where id = ?
    But what we're actually seeing is:
    1. SchoolDAO.delete(id)
    Hibernate: DELETE from School where id = ?
    And hence the foreign key constraints.
    Was wondering if someone else here has run into this. Someone on the Hibernate forums suggested using an Interceptor, but the Hibernate3 interceptors don't give us access to the Session to allow us to do a bulk update to null out these references. Apparently the interceptor javadoc says that the interceptor is basically there to change properties on the object in question and should not involve the session at all.
    We then looked at implementing an Event, and that worked, but was not called for every cascade deleted event. We have a lot of cascade activity in our database, so that was a little disappointing.
    We had briefly considered manually nulling out that FK in the DAO itself, but that would not work with the large amount of Hibernate driven cascade deletion that goes on in our app (Hibernate does not call our DAO every time it cascade deletes an entity).
    Would greatly appreciate any pointers on this subject. We're hoping that others have run into this as well.
    thanks.

    I'm not sure why you'd expect that given that there's
    not really an equivalent object oriented operation -
    if you want to relinquish the object in the OO scheme
    of things you have to null all the references to it;
    you can't just say "make everything that points to
    this object null".I can field that question. We came from EJB 2.x where in the event that you deleted a School entity bean using ejbRemove() you would see the following queries generated:
    UPDATE Student set schoolId = NULL where schoolId = ?
    DELETE from School where id = ?
    Basically, it would manage the relationship for you. I know it's a completely different system but we were a little surprised to learn that Hibernate did not do this on its own as well.

  • How can I have multiple instances of a column that itself holds a foreign key reference?

    I am new to Visual Studio so to start learning it I first of all downloaded a sample available at https://code.msdn.microsoft.com/ADPNET-Entity-Framework-2d1160cb and started working around it. Since I have fairly good knowledge of VB6 and SQL it did
    not take much time for me to understand the whole pattern the sample is based on. Had Microsoft given a detail explanation or a walk through of the sample it would have been much easier to understand the basics. However, I somehow managed to work around it
    and have build a small desktop application in wpf using Entity Framework and MVVM. But a point has come where I have got completely stuck up finding no way out. The problem is as under:
    I have two tables. 1 Advocate and 2 Party. Table Advocate would contain names of advocates and would have a primary key. Similarly Party would have names and their respective primary keys.
    Then I have another two tables 1. Case and 2 CaseDetail. Table Case would simply hold three columns: 1. CaseId 2. CaseNo and 3. Year. Table CaseDetail would have CaseDetailId as a primary key the CaseId as a Foreign Key. Now what I need is that a particular
    case could have multiple advocates and multiple petitioners. So the table CaseDetail would have two columns to hold advocateId and PartyId as a Foreign Keys. 
    If you look at the sample referred above you would not find how to deal with such a case. When I follow the pattern of the sample I get host of design time and runtime errors. 
    Therefore, please suggest what strategy should be adopted in a scenario described above while developing WPF application using Entity Framework and MVVM.

    I am new to Visual Studio so to start learning it I first of all downloaded a sample available at https://code.msdn.microsoft.com/ADPNET-Entity-Framework-2d1160cb and started working around it. Since I have fairly good knowledge of VB6 and SQL it did not
    take much time for me to understand the whole pattern the sample is based on. Had Microsoft given a detail explanation or a walk through of the sample it would have been much easier to understand the basics. However, I somehow managed to work around it and
    have build a small desktop application in wpf using Entity Framework and MVVM. But a point has come where I have got completely stuck up finding no way out. The problem is as under:
    I have two tables. 1 Advocate and 2 Party. Table Advocate would contain names of advocates and would have a primary key. Similarly Party would have names and their respective primary keys.
    Then I have another two tables 1. Case and 2 CaseDetail. Table Case would simply hold three columns: 1. CaseId 2. CaseNo and 3. Year. Table CaseDetail would have CaseDetailId as a primary key the CaseId as a Foreign Key. Now what I need is that a particular
    case could have multiple advocates and multiple petitioners. So the table CaseDetail would have two columns to hold advocateId and PartyId as a Foreign Keys. 
    If you look at the sample referred above you would not find how to deal with such a case. When I follow the pattern of the sample I get host of design time and runtime errors. 
    Therefore, please suggest what strategy should be adopted in a scenario described above while developing WPF application using Entity Framework and MVVM.

  • Easy way to display lookup value of a foreign key reference vs value itself

    I've figured out how to do this for a Form
    http://www.dba-oracle.com/htmldb/t_lov_list_values_master_parent_child.htm
    ...but not for a report which lists the data row by row.
    Given table Centre with the following columns:
    ID
    Name
    Department_ID
    and given table Department with the following columns:
    ID
    Name
    When the report runs on the Centre table it simply queries ID, Name and Department_ID from the database, and then displays each column as is.
    Instead of displaying the Department_ID from the Centre table (which is a number and not very informational), how can I make it display the Name from the department table?
    I have lots of other similar fields which need to be displayed in this way so I'm hoping there isn't a ton of configuration/coding I need to do.

    Hi,
    Try report query
    SELECT a.id,
      a.name,
      b.name dept_name
    FROM centre a,
      department b
    WHERE a.department_id = b.idBr,Jari

  • EServer Model Diagram and Cross Reference schema -Foreign key

    Hi,
    I am doing reverser engineering to generate ER diagram from Designer. Version of designer I am using is 10.2.0.2.
    While trying to generate SMD (Server model Diagram) from existing database schema, it is failing on generating foreign keys reference to other schema and its table.
    Can anybody help me to solve the this problem ?
    Viral Dave

    Note 236266.1
    CDS-11305 When Capturing a Foreign Key to a Table in Another Schema.
    * symptom: CDS-11306 Warning: Foreign Key <name> not processed because dependent Primary Key <name> not chosen for generation or does not exist in target database
    * symptom: Foreign Key to a Table in Another Schema is not Capture Designed
    * cause: This functionality is NOT supported by Oracle Designer. See: Bug 885654 FOREIGN KEYS TO DIFFERENT SCHEMA THAN BASE TABLE NOT SUPPORTED
    fix:
    In release 4.4 (6.5.89) and beyond, this functionality is still not
    supported, but the following message is issued for clarification:
    CDS-15302 Warning: <schema> clause of the relation referenced by foreign
    key constraint ... is unsupported
    Sorry....Designer will not capture that.
    Michael

  • Performance degradation when using foreign keys

    Hi,
    I face drastic performance degradation when I add foreign keys to a table and perform insert / update on that table.
    I have a row store table to  which I need to insert around 1,50,000 records.
    If the table has no foreign key reference it takes maximum of 5 seconds but if the same table has references to other tables (in my case there are 3 references), the processing speed reduces drastically to 2 minutes.
    Is there any solution / best practice that can help me in gaining performance (processing speed) in this situation?
    Thanks
    S.Srivatsan

    Hi Sri,
    When you perform one insert in any database table which is having foreign key relationships, it will check the corresponding parent tables to check whether the master data is available or not. If your table is having 2 foreign key relationship, it happen twice per insert. Hence the performance will degrade. This is one of the reasons why ECC  doesn't establish foreign key relationship in the back end database. The case is not just for INSERT, for UPDATE & DELETE the same is applicable.
    Sreehari

  • 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

  • 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?

  • SQL data modeller -- how to create 1 to 1 relationship foreign key ?

    hi guys...
    i got 2 tables..
    table 1 - CFR
    CFR_ID = primary key
    table 2 - USER_PLAN
    USER_ID = primary key
    PLAN_ID,
    CFR_ID = foreign key reference (table 1)
    The business flows go like this..
    insdie CFR table, it contain all records / transactions of a particular user/plan. everytime a new transaction occurs for a plan/user, a new CFR_ID / row will be generated.
    after which, the newly generated CFR_ID for the new row , will be updated to the CFR_ID in USER_PLAN
    Thus, there is always a 1 to 1 relationship between the 2 table regardless how many CFR_ID is generated for a particular USER_PLAN. as the CFR_ID in the USEr_plan table will always be the latest one generated inside the CFR table.
    However, in the data modeller, i am unable to create such foreign key relationship... ANY idea how do i create a 1 on 1 foreign key relationship ? or there is no such way..
    Thanks and Best Regards,
    Noob

    Hi philips,
    Thanks for the wonderful reply..
    Just to double comfirm with you,
    even if i had set a unique constraint on CFR_ID(foreign key column), inside the relationship model, the relationship between the foreign key is still showing as a 1:m relationship right ?
    just that a character 'U' will appear beside the CFR_ID column.
    However the diagraphm is still showing a 1:M relationship.
    is this correct ?
    Regards,
    Noob

  • Optional Composite Foreign Key

    The tool doesn't seem to be handling this correctly when some of the columns are mandatory and others are nullable. I have a composite foreign key where one column is part of the primary key and the other is not. In the Columns properties of the Table dialog, it shows the column that is part of the primary key as mandatory. But on the diagram, the "red dot" indicator is missing. It also give me an error on the Foreign Keys properties when I click OK or Apply.

    No, You cant get a composite keys based on two different primary keys. Reason for this can be like unique index is being used when we create any primary key. When we create a composite primary key, one index is created for the two fields and thus one index store the values for two columns involved in the composite primary key and these values are stored in pairs. So when any foreign key references this composite primary key, it will match the data in pairs as it is stored in the index(unique index).
    Now when we say to create a composite foreign key based on two different primary keys , we are taking into account two indexes for two different fields. So there is no pairing in these two indexes. So when we will create foreign key using this, it will not get a pair of values or we can say oracle cant get us consistent pair of values from two indexes. So maintaining integrity will not be possible.
    Yes you can create two foreign keys on one column which can refer two different primary keys.
    Regards

  • Composite Foreign Key

    Dear All
    please correct this syntax for composite foreign key.
    Ater Table emp_pays
    Add Constraints emp_pt_fk Foreign Key(emp_id,pt_id) Referenes emp(emp_id),pay_type(pt_id);
    Thanks in advances
    Regards,

    No, You cant get a composite keys based on two different primary keys. Reason for this can be like unique index is being used when we create any primary key. When we create a composite primary key, one index is created for the two fields and thus one index store the values for two columns involved in the composite primary key and these values are stored in pairs. So when any foreign key references this composite primary key, it will match the data in pairs as it is stored in the index(unique index).
    Now when we say to create a composite foreign key based on two different primary keys , we are taking into account two indexes for two different fields. So there is no pairing in these two indexes. So when we will create foreign key using this, it will not get a pair of values or we can say oracle cant get us consistent pair of values from two indexes. So maintaining integrity will not be possible.
    Yes you can create two foreign keys on one column which can refer two different primary keys.
    Regards

  • Primary key foreign key remove problem

    hi expretrs,
    I create 5 tables in ddic.
    1. zpr_cmp Company Master
    2. zpr_dpt Department Master
    3. zpr_dsg Designation Master
    4. zpr_emp Employee master.
    5. zpr_slm Salary Master.
    Foreign key reference in zpr_emp from table 1,2 and 3 created and
    table zpr_emp has
    cmpcd, Company Code
    empcd, Employee Code
    dptcd , Department Code
    dsgcd Designation Code
    as key fields.
    I have upload data and create module pool and reports.
    My problem that hr person say that we want to change deptcd/dsgcd of employee (zpr_emp) and
    dptcd and dsgcd is as key fields in zpr_emp when i change the table zpr_emp and remove
    two key fields dptcd/dsgcd and active error display.
    I also try with se14 (Activate and Adjust database) but error still.
    how can i remove key field from zpr_emp and active table without loss data and without any change of
    module pool/reports
    pl. help

    Diagnosis
    ZPR_EMP table is defined as a check table. For reasons of consistency, changes to the primary key of the table are not allowed.
    Procedure
    If it is essential that you change the primary key, you must delete the relevant foreign keys. Refer to the where-used list to find all tables containing a field that is checked against this table. Delete the foreign keys for these fields.
    If necessary, maintain the deleted foreign keys again.
    Value table - It's a field in a domain it helps in domain level data validation.
    Check table - unlike value table it helps in feild level data validation.
    The relational data model contains not only tables, but also relationships between tables. These relationships are defined in the ABAP/4 Dictionary by foreign keys. An important function of foreign keys is to support data integrity in the relational data model. Foreign key fields may assume only those values allowed by the check table, in other words, values occurring in the primary key of the check table.
    A foreign key provides a link between two tables, for eg.,T1 and T2 by including a reference in table T1 to the primary key of table T2. For this purpose, Foreign key fields assigned to the primary key fields of T2 are included in T1. Table T1, which is the one being checked, is called a foreign key table, and table T2 is called a check table. The terms dependent (foreign key) table and referenced (check) table are also used.
    VALUE TABLE:If the domain of the check field has a value table, this is proposed by the system as check table in the foreign field maintenance. The key fields of the value table are in this case assigned fields of the foreign key table with the same domain. These fields may assume only those values allowed by the value table.
    The value range of the domain can be defined by specifying value table.All table fields referring to this domain can then be checked against the corresponding field of this value table.In order the check can be executed, a foreign key must be defined for the value table.

  • 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.

  • Create a foreign key from a field that is part of a mulitple primary key

    Hi,
    i had a table named T_A, with a double primary key : (A,B)
    Then i created a table named T_B with a field : C.
    I want this field T_B.C to take only values that already exist in field T_A.A.
    So i tried to create a foreign key on my field T_B.C, pointing on the field T_A.A : an error message appeared "not possible to create a foreign key on a field that is not a primary key".
    How can i solve this....? If U have any idea, please mail me !!
    THANX very much.

    Add column A as foreign key into the table T_BHow?
    (was the question from the original poster. Adding a column to table T_B that happen to have same name as the corresponding column in table T_A would not allow you to add the foreign key).
    SQL> create table t_a (a number, b number, primary key(a, b)) ;
    Table created.
    SQL> create table t_b(a number, c number, constraint foreign key references t_a(a)) ;
    create table t_b(a number, c number, constraint foreign key references t_a(a))
    ERROR at line 1:
    ORA-02270: no matching unique or primary key for this column-list
    SQL>

Maybe you are looking for

  • Steps to enhance a datasource from SAP CRM

    Dear Forum, Could you please provide me with some document to enhance a datasource from SAP CRM. Is it any different from enhancement of datasource from ECC datasources, Thanks and regards,

  • Bex Issue : before aggregation

    Hi, I have a problem in Bex that I thought to solve with the "before aggregration" option in Bex Analyzer but this doesn't seem to be possible. My query looks initially like this for 1 shipment 1344601 that is linked to 2 deliveries Shipment Delivery

  • Remove .0 from formula

    i created a formula totext({COMPONTD.CPPODT},' ',0) to remove the .00 from the field(the field is a number to start with) then i use left(totext,3) i get an error, not sure what the error is because it doesnt tell, is the above formula to remove the

  • V$SESSION source table

    Hi All, what is base table for V$SESSION ? And in which schema i can found it ? Actually i want to search for a particular user login time and his PC information before 1 month Regards

  • Authentification Open Document Link

    Hello I'm using WebI in BO Edge with SAP authentification. The Report has an open document Link to a Crystal Reports. The Databas configuration of this Report (CMC) is set to SSO. When I stert the WebI and click on the Link, a window pops up with a l