Note that there are some explanatory texts on larger screens.

plurals
  1. PORecommended approach to merging two tables
    primarykey
    data
    text
    <p>I have a database schema like this:</p> <pre><code>[Patients] [Referrals] | | [PatientInsuranceCarriers] [ReferralInsuranceCarriers] \ / [InsuranceCarriers] </code></pre> <p>PatientInsuranceCarriers and ReferralInsuranceCarriers are identical, except for the fact that they reference either Patients or Referrals. I would like to merge those two tables, so that it looks like this:</p> <pre><code>[Patients] [Referrals] \ / [PatientInsuranceCarriers] | [InsuranceCarriers] </code></pre> <p>I have two options here</p> <ul> <li>either create two new columns - ID_PatientOrReferral + IsPatient (will tell me which table to reference)</li> <li>or create two different columns - ID_Patient and ID_Referral, both nullable.</li> </ul> <p>Generally, I try to avoid nullable columns, because I consider them a bad practice (meaning, if you can live w/o nulls, then you don't really need a nullable column) and they are more difficult to work with in code (e.g., LINQ to SQL).</p> <p>However I am not sure if the first option would be a good idea. I saw that it is possible to create two FKs on ID_PatientOrReferral (one for Patients and one for Referrals), though I can't set any update/delete behavior there for obvious reasons, I don't know if constraint check on insert works that way, either, so it looks like the FKs are there only to mark that there are relationships. Alternatively, I may not create any foreign keys, but instead add the relationships in DBML manually.</p> <p>Is any of the approaches better and why?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload