简体   繁体   English

数据库设计,使一张表指向多个递归指针

[英]database design, make one table to point several and some kind of recursive pointers

I have some medical information I would like to store in a relational database but do not know hot to model it the best way.

The issue here is I have several fields that subdivide in other fields that at the same time subdivide into other fields....

For instance I have this sql code:

 CREATE TABLE Distribution_patterns(
              id_Distribution_pattern  INTEGER  NOT NULL PRIMARY KEY,
              LEFT_SIDE_VIEW           VARCHAR(40)  NOT NULL,
              RIGHT_SIDE_VIEW          VARCHAR(40)  NOT NULL,
              dorsal_view              VARCHAR(10 ) NOT NULL,
              ventral_ view            VARCHAR(10 ) NOT NULL,              
              CONSTRAINT uc_Info_d_p UNIQUE (id_Distribution_pattern)           
            );


CREATE TABLE lymph_nodes (
              id_lymph_nodes       INTEGER  NOT NULL PRIMARY KEY,
              MANDIBULAR           VARCHAR(40)  NOT NULL,
              scapular             VARCHAR(40)  NOT NULL,
              INGUINAL             VARCHAR(10 ) NOT NULL,
              popliteal            VARCHAR(10 ) NOT NULL,              
              CONSTRAINT uc_Info_l_n UNIQUE (id_lymph_nodes)           
            );

CREATE TABLE evaluation(
          ID_evaluation            INTEGER  NOT NULL PRIMARY KEY,
          Distribution_pattern     INTEGER ,
          lymph_node               INTEGER ,
          Musculoskeletal_system   INTEGER ,
          FOREIGN KEY (Distribution_pattern) references Distribution_patterns (id_Distribution_pattern),
          FOREIGN KEY (lymph_nodes)    references lymph_nodes (id_lymph_node),
          FOREIGN KEY (Musculoskeletal_system) references Musculoskeletal_system_parts (id_Musculoskeletal_system),
          CONSTRAINT uc_Info_evaluation UNIQUE (ID_evaluation)           
        );
  • Distribution pattern
    • LEFT SIDE VIEW
    • RIGHT SIDE VIEW
    • dorsal view
    • Ventral view
  • lymph nodes
    • MANDIBULAR
    • scapular
    • INGUINAL
    • popliteal
  • Musculoskeletal system
    • Gait assessment
    • VALUATION OF TROT
    • PALPATION
      • TIP thoracic
        • Elbow and forearm
        • CARPO AND FINGERS
      • TIP pelvic
        • PELVIS
        • KNEE
        • HOCK
      • specific tests
        • CAJON TEST
        • Ortolani TEST
        • OTHER

Of course this is not the whole data as there are like 200 fields and 14 categories.....

Is it correct to do this approach for "Musculoskeletal system" that has more subdivisions?

Is there other way to model this kind of situation, or I need to have several tables where an ID is the pointer to other table which has a pointer to other table and so on....

If I would like to make a query that gives a huge table with all data for "medical evaluation" what would be the best approach, several joins ON id?

This is a potentially large database schema, so I will just focus on Musculoskeletal system. 这是一个潜在的大型数据库架构,因此我仅关注肌肉骨骼系统。 Before I get into that, though, I should mention the importance of database normalization. 在开始之前,我应该提到数据库规范化的重要性。 It's important! 这一点很重要! And for many reasons. 并且有很多原因。 Chiefly, by designing a good, normalized, database now you save yourself problems down the road while ensuring the integrity and reliability of your data. 首先,现在通过设计一个良好的,规范化的数据库,您可以在确保数据完整性和可靠性的同时,避免在将来遇到的麻烦。 Always keep in the back of your mind "How will this database grow", "What if i need to add more systems or views or distribution patterns", etc. Do yourself, an your employer, a favor and read up on in. A brief overview can be read here: http://databases.about.com/od/specificproducts/a/normalization.htm 始终牢记“该数据库将如何增长”,“如果我需要添加更多系统,视图或分发模式该怎么办”之类的内容。对自己,你的雇主,帮忙和继续读吧。简要概述可以在这里阅读: http : //databases.about.com/od/specificproducts/a/normalization.htm

To the database design: 到数据库设计:

You want to keep redundant column and columns that are subsets of other columns out of aa table and into its own. 您想将多余的列和作为其他列子集的列保留在一个表之外,并保留在自己的表中。 For instance, look at your Lymph Node table. 例如,查看您的Lymph Node表。 What if a year from now you realize you need to add another lymph node? 如果一年后才意识到您需要增加另一个淋巴结怎么办? Or remove one? 还是删除一个? Or what if you are only looking at one node from a client? 或者,如果您仅查看来自客户端的一个节点怎么办? Instead of doing it your way, tie the table to a larger object (Im not a doctor so Im not sure what the anser is) like Patient or Lymph Systems. 与其按照自己的方式做,不如将桌子绑在一个更大的物体上(我不是医生,所以我不确定是谁。),例如Patient或Lymph Systems。 Or both. 或两者。 Example: 例:

A patients has many systems (one to many relationship between patient table and systems table) A lymph system has many organs(one to many relationship between lymp system and organs) A system, or organ, has many test (a one to many relation ship between systems and tests). 一个病人有很多系统(病人表和系统表之间是一对多的关系)淋巴系统有很多器官(淋巴系统和器官之间是一对多的关系)一个系统或器官有很多测试(一对多的关系)在系统和测试之间)。

Example: 例:

TablePatient TablePatient

PatientId (int PK) PatientId(int PK)

PatientFName(string) PatientFName(串)

PatientLName(string) PatientLName(串)

This table should have only data pertaining to an individual patient 该表应仅包含与单个患者有关的数据

TableSystems TableSystems

SystemId(int PK) SystemId(int PK)

SystemName(String) 的SystemName(字符串)

SystemDescription(string) SystemDescription(串)

This table should have only columns specific to all systems. 该表应仅包含所有系统的特定列。 Systems might be lymph systems, respiratory systems, excretory systems, etc. 系统可能是淋巴系统,呼吸系统,排泄系统等。

TablePatient_TableSystems TablePatient_TableSystems

Patient_System_ID(int PK) Patient_System_ID(int PK)

PatientID(int FK) PatientID(整数FK)

SystemID(int FK) SystemID(整数FK)

You cant have many to many relationships. 你不能有很多对很多的关系。 This table resolves that. 该表解决了该问题。 If you didnt have this, you would need to keep redundant records in each table for each patient/system 如果没有,您将需要在每个表中为每个患者/系统保留冗余记录

TableOrgans TableOrgans

OrganID(int PK) OrganID(int PK)

OrganName(string) OrganName(串)

OrganDesc(string) OrganDesc(串)

TableOrgan_TableSystem TableOrgan_TableSystem

Organ_SystemID(int PK) Organ_SystemID(int PK)

OrganID(int FK) OrganID(int FK)

SystemID(int FK) SystemID(整数FK)

Resolves the many to many for systems and organs 解决了许多系统和器官问题

Now for tests. 现在进行测试。 Are test specific to organs or systems? 测试特定于器官或系统吗? Or both? 或两者? This example will say both 这个例子会说

TableTest TableTest

TestID TestID

TestName 测试名

TestDesc TestDesc

TestCost TestCost

Tabel_Test_Stytem Tabel_Test_Stytem

TestSytemID(int PK) TestSytemID(int PK)

TestID(int FK) TestID(int FK)

SystemID(int FK) SystemID(整数FK)

Tabel_Test_Organ Tabel_Test_Organ

TestSytemID(int PK) TestSytemID(int PK)

TestID(int FK) OrganId(int FK) TestID(int FK)OrganId(int FK)

There's a lot here, so I think this is a good place to stop. 这里有很多东西,所以我认为这是个好地方。 Read through data normalization and when you have questions, post back here (or message me). 通读数据标准化,如果有疑问,请发回此处(或给我发消息)。

You are talking about a hierarchical structure. 您正在谈论层次结构。 If I were asked to do it, I will en up with two table: a data and a reference. 如果要求我这样做,我将使用两个表:一个数据和一个引用。

Evaluation table 评估表

  • EvaluationId EvaluationId
  • PartId PARTID
  • EvaluationText EvaluationText

Reference table 参考表

  • PartId PARTID
  • GroupId GroupId的
  • PartDesc PartDesc

The reference table with contain these: 参考表包含以下内容:

PartId  GroupId PartDesc
0   null    Evaluation
1   0   Distribution pattern
2   1   LEFT SIDE VIEW
3   1   RIGHT SIDE VIEW
4   1   dorsal view
5   1   Ventral view
6   0   lymph nodes
7   6   MANDIBULAR
8   6   scapular
9   6   INGUINAL
10  6   popliteal
11  0   Musculoskeletal system
12  11  Gait assessment
13  11  VALUATION OF TROT
14  11  PALPATION
15  14  TIP thoracic
16  15  Elbow and forearm
17  15  CARPO AND FINGERS
18  14  TIP pelvic
19  18  PELVIS
20  18  KNEE
21  18  HOCK
22  11  specific tests
23  22  CAJON TEST
24  22  Ortolani TEST
25  22  OTHER

Now that we have a neat table to use. 现在我们有了一个整洁的表。 How are we going to use it? 我们将如何使用它? Well, recursive CTE, of course. 当然,递归CTE。 You didn't mention the DB Engine, but almost every major DBMS can do it except for MySQL. 您没有提到DB Engine,但是除了MySQL之外,几乎所有主要的DBMS都可以做到。 You can either look up this cool feature yourself or let us know your DB Engine and we can continue this discussion. 您可以自己查找此炫酷功能,也可以让我们知道您的数据库引擎,我们可以继续进行讨论。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM