Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I model a join table with parent-child tables?
    primarykey
    data
    text
    <p>I have a table, <code>VisitTest</code>, that joins patient visits (<code>Visit</code> table) to diagnostic tests (<code>Test</code> table) given during that appointment. The <code>Test</code> table is a superclass (parent table) of tables containing actual tests. Each child table has the test parameters and results (1).</p> <p>The <code>Test</code> table contains metadata. Columns like <code>id</code>, <code>name</code>, <code>description</code>, <code>status</code>, etc are stored here. The child tables (inherit, in OOP terms, from the <code>Test</code> table) and have their own test-specific fields. Each test parameter is its own column. The child tables have an id column that represents the test instance. For example we may have 10 tests but each test was given 100 times so we have 1000 test instances.</p> <p>For some reason, I can't figure out how to model the relationships. That's where I need help.</p> <p>Am I missing another join table to make this work? How to I join the visit number to the instance of the test? Given a visit id, how do I find the specific tests given during that visit? How do I model the relationship between the parent and child tables?</p> <p>Here are three tables I have. The TestABC table is a specific test and there will be many other tests like it. The visit table and everything related to it, minus the linkage to tests, is complete.</p> <pre><code>CREATE TABLE [dbo].[Visit]( [Id] [int] IDENTITY(1,1) NOT NULL, [ColumnV1] [nchar](10) NULL, CONSTRAINT [PK_Visit] CREATE TABLE [dbo].[Test]( [Id] [int] IDENTITY(1,1) NOT NULL, [Name] [nvarchar](50) NULL, [Description] [nvarchar](50) NULL, CONSTRAINT [PK_Test] CREATE TABLE [dbo].[TestABC]( [Id] [int] NOT NULL, [Parameter1] [nvarchar](50) NULL, [Parameter2] [nvarchar](50) NULL, CONSTRAINT [PK_TestABC] </code></pre> <p>(1) I deleted my earlier question about choosing between key-value pair and entity-type tables. I opted to avoid venturing down the KVP road due to less-than-blissful report building experience with KVP and my preference for strongly-typed values.</p>
    singulars
    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.
 

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