我应该有一个主设备表还是多个属性表?

问题描述 投票:0回答:2

我正在尝试设计的设备数据库中存在以下情况。我目前有3个表格,详细介绍了3种不同类型的设备和1个表格,以保持所有3个表格中所有ID的独特性。如下:

CREATE TABLE EQUIPMENT
(
    /*Primary key*/
    EQUIPMENT_ID         VARCHAR(30),

    PRIMARY KEY (EQUIPMENT_ID)
);

CREATE TABLE PIPING
(
    /*Primary key*/
    EQUIPMENT_ID         VARCHAR(30), 

    /*Generic Fields*/
    STATUS               VARCHAR(1),
    INSPECTION_STATUS    VARCHAR(1),
    REMEDIATION_STATUS   VARCHAR(1),

    /*Specific properties for piping equipment*/
    OUTSIDE_DIAMETER     FLOAT,
    WALL_THICKNESS       FLOAT,

    /*About another additional 50 specific fields*/

    PRIMARY KEY (EQUIPMENT_ID),
    FOREIGN KEY (EQUIPMENT_ID) REFERENCES EQUIPMENT(EQUIPMENT_ID)
);

CREATE TABLE VESSELS
(
    /*Primary key*/
    EQUIPMENT_ID         VARCHAR(30), 

    /*Generic Fields*/
    STATUS               VARCHAR(1),
    INSPECTION_STATUS    VARCHAR(1),
    REMEDIATION_STATUS   VARCHAR(1),

    /*Specific properties for vessel equipment*/
    DISHED_END_THICKNESS FLOAT,
    DESIGN_CODE          VARCHAR(25),

    /*About another additional 50 specific fields*/

    PRIMARY KEY (EQUIPMENT_ID),
    FOREIGN KEY (EQUIPMENT_ID) REFERENCES EQUIPMENT(EQUIPMENT_ID)

);

CREATE TABLE TANKS
(
    /*Primary key*/
    EQUIPMENT_ID            VARCHAR(30), 

    /*Generic Fields*/
    STATUS                  VARCHAR(1),
    INSPECTION_STATUS       VARCHAR(1),
    REMEDIATION_STATUS      VARCHAR(1),

    /*Specific properties for tank equipment*/
    FLOATING_ROOF_DIAMETER  FLOAT,
    FLOATING_ROOF_THICKNESS FLOAT,

    /*About another additional 50 specific fields*/

    PRIMARY KEY (EQUIPMENT_ID),
    FOREIGN KEY (EQUIPMENT_ID) REFERENCES EQUIPMENT(EQUIPMENT_ID)

);

将所有这些表组合成一个包含150列的主设备表是否更好?或者将他们分成小组,记住以下内容:

  • 管道,容器和储罐表中的所有区域都具有1:1的关系,并且都依赖于主键。

从引用stackoverflow社区上关于此主题的其他帖子...

MySQL: multiple tables or one table with many columns?

由于主键和列之间的1:1关系,这个场景的最佳设计似乎是一个包含许多列的大表,但我还不确定并希望别人对此事的想法。

mysql database-design
2个回答
1
投票

一些一般性意见,评论时间过长:

EQUIPMENT_ID         VARCHAR(30) -- There's almost certainly no good reason for this not to be an auto-incrementing integer

STATUS               VARCHAR(1) -- CHAR(1) uses less memory and achieves the same thing.

OUTSIDE_DIAMETER     FLOAT -- It seems more plausible to me that this would be a DECIMAL, and likewise for all the other FLOATs

最后,如果您决定切换到EAV模型,请考虑为不同的数据类型设置单独的表,因此所有DECIMAL类型的东西都放在一个表中,而所有字符串类型的东西放在另一个表中。


1
投票

有一种技术与此相关。它被称为类表继承。有更多细节here

© www.soinside.com 2019 - 2024. All rights reserved.