数据库设计/可扩展性 - 新的"类型ID"具有可能可变数量的所需列

时间:2017-08-15 19:33:07

标签: database-design scalability

我正在设计一个应用程序的数据库,该应用程序将管理我公司拥有的资产。说我有以下表格:

+-----------------+
| Component Type  |
+-----------------+--------------------------+
| ComponentTypeID | ComponentTypeDescription |
+-----------------+--------------------------+
| 1               | Server                   |
| 2               | PC                       |
| 3               | Database                 |
+-----------------+--------------------------+

+-----------+
| Component |
+-----------------+---------------+
| ComponentTypeID | ComponentName |
+-----------------+---------------+
| 1               | Server1       |
| 1               | Server2       |
| 2               | PC1           |
| 3               | Database1     |
| 3               | Database2     |
+-----------------+---------------+

我希望将所有组件存储在"组件"表。每个ComponentTypeID都需要额外的详细信息,但每个组件的详细信息会有所不同。例如,服务器和PC都有"操作系统"和数据库将有" DBMS"。

据我所知,在表中填充空值的列是不好的做法。例如:

+-----------+
| Component |
+-----------------+---------------+---------------------+------------+
| ComponentTypeID | ComponentName | OperatingSystem     | DBMS       |
+-----------------+---------------+---------------------+------------+
| 1               | Server1       | Windows Server 2012 | (null)     |
| 1               | Server2       | Windows Server 2012 | (null)     |
| 2               | PC1           | Windows 10          | (null)     |
| 3               | Database1     | (null)              | SQL Server |
| 3               | Database2     | (null)              | MySQL      |
+-----------------+---------------+---------------------+------------+

我也知道单个列的多用途是不好的做法。例如:

+-----------+
| Component |
+-----------------+---------------+----------------------+
| ComponentTypeID | ComponentName | OperatingSystem/DBMS |
+-----------------+---------------+----------------------+
| 1               | Server1       | Windows Server 2012  |
| 1               | Server2       | Windows Server 2012  |
| 2               | PC1           | Windows 10           |
| 3               | Database1     | SQL Server           |
| 3               | Database2     | MySQL                |
+-----------------+---------------+----------------------+

处理此问题的好方法是什么?如果我想允许我的用户将ComponentTypes添加到ComponentType表中,将来我需要考虑什么?

0 个答案:

没有答案