I have a situation where I need to apply referential integrity
(RI) to specific data. In this case, selected rows of a given
column will contain the reference key to the primary key of a
different table. The problem is that the reference column is
not mandatory for all rows. When the reference column is NULL,
it should not be referred by the parent table.
For example, in a telephonic appointment form, a patient may make an
appointment even if they do not know their user id assigned by the
hospital. The user id field would be null, but the name is
entered manually into the record; however, in the event the user id
is entered, it needs to fetch the patient name from the master
Is there a solution for this problem?
Answer: This can be
accomplished with a
Referential Integrity (RI) is used to enforce entity
relationships between tables.
One example of such a relationship might be that a customer may
place many orders, but each order only belongs to one customer.
In your situation, there is a one-to-many between patients and
Obviously, this relationship cannot be enforced if you leave
"orphan" appointments, which are not hooked to a patient.
Since the patients using your system may not know their user id
assigned by the hospital, you need a candidate key.
The candidate key can either be made up, like an Oracle sequence, or
it can be a unique combination of information you do have.
In your case, you may not know the hospital userID, but you can make
a unique name from the first 5 letters of the last name concatenated
with the date of birth, something like this:
Sam Jones, born 3/13/1950
key - jones3131950
I have a good book on
Oracle Design that might help.