简体   繁体   English

布尔表SQL的最佳方法

[英]boolean table sql best approach

I want to store the current situation of a patient 我想存储患者的当前状况

  • Entry 条目
  • In Body Treatment 体内治疗
  • High Medical 高级医学

What would be the best approach to store a boolean table like this? 像这样存储布尔表的最佳方法是什么?

I was thinking 我刚在想

ID_STATUS   INT
ID_PATIENT  INT 
ENTRY       BOOL
BODY_TREATMENT  BOOL
HIGH_MEDICAL    BOOL

Is this a good approach or only a table like the following is needed ? 这是一个好方法还是只需要一个如下表?

ID_STATUS         INT
ID_PATIENT        INT
CURRENT_STATUS    VARCHAR

Store your CURRENT_STATUS possibilities in a lookup table. 将您的CURRENT_STATUS可能性存储在查找表中。 You can use a surrogate key or not. 您是否可以使用代理键。 This is personal preference but should probably follow what the rest of the database looks like. 这是个人喜好,但应该遵循数据库其余部分的样子。

Boolean columns are somewhat of a code smell. 布尔列有点代码味道。 "Flags" like this can often be refactored into better relational structures. 这样的“标记”通常可以重构为更好的关系结构。 In your case, would it make sense if two statuses were true at the same time? 在您的情况下,如果两个状态同时为真,是否有意义?

If you don't care about when one situation stops and the next one starts, all you need is: 如果您不关心何时一种情况停止而下一种情况开始,那么您所需要做的就是:

id_patient
id_situation

That's an oversimplification of course, because a patient can have more than one visit and each visit would have it's own situation. 当然,这过于简单了,因为患者可以进行多次就诊,而每次就诊都有自己的情况。

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

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