Note that there are some explanatory texts on larger screens.

plurals
  1. POExpressing an is-a relationship in a relational database
    primarykey
    data
    text
    <p>I was wondering if there is a clean way to represent an is-a relationship as illustrated by this example:</p> <p>This DB stores recording times for three types of programs: movies, game shows, drama. In an object oriented sense each of these is-a program. Each of these subclasses have different properties. Here are the tables (fk prefix indicates a foreign key):</p> <p><em>movie</em><br> id<br> name<br> fkDirector<br></p> <p><em>gameShow</em><br> id<br> name<br> fkHost<br> fkContestant<br></p> <p><em>drama</em><br> id<br> name<br></p> <p>In OO terms the record table would in sense look like this:<br><br> <em>record</em><br> id<br> fkProgram<br> startTime<br> endTime<br></p> <p>The only way I can think of doing this without violating the normal forms is to have three record tables namely <em>recordMovie</em>, <em>recordGameShow</em>, and <em>recordDrama</em>.</p> <p>Is there a way to consolidate these tables into one without violating the principles of database normalization?</p> <p>Here are some non-working examples to illustrate the idea:</p> <p><em>program</em><br> id<br> fkMovie<br> fkGameShow<br> fkDrama<br></p> <p>This table violates the first normal form because it will contain nulls. For each row only one of the 3 entries will be non null.</p> <p><em>program</em><br> id<br> fkSpecific ← fkMovie OR fkGameShow OR fkDrama<br> fkType ← would indicate what table to look into<br></p> <p>Here I will not be able to enforce referential integrity because the fkSpecific could potentially point to one of three tables.</p> <p>I'm just trying to save the overhead of having 3 tables here instead of one. Maybe this simply isn't applicable to an RDB.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    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