1

I'm designing a database table for a manufacturing company, amongst the tables required is a part applications table (meaning this product applies to x and y product), my current issue is that most product lines have about 3 to 10 applications, but 2 specific lines have up to 100 applications.

At first I thought about storing product applications as a comma separated string, but that would violate the first normal form.

Then I read about storing said applications as a blob, however in the interest of both search optimization and general DB performance this doesn't seem to be a possibility.

My question is this, is there a way to store part applications in a table without having to create the 70+ columns, while mantaining normal forms and not compromising performance??

4

4 回答 4

4

为了满足not compromising performance要求,您需要确切地知道您将运行哪些查询。

但在像这样的正常情况下,你会有一个多:多映射表......

CREATE TABLE map_part_application (
  part_id         INT,
  application_id  INT,
  PRIMARY KEY (part_id, application_id)
)


INSERT INTO map_part_application VALUES (1,1)
INSERT INTO map_part_application VALUES (1,2)
...
INSERT INTO map_part_application VALUES (1,100)
INSERT INTO map_part_application VALUES (2,1)
INSERT INTO map_part_application VALUES (2,2)
...
INSERT INTO map_part_application VALUES (1,12)

我建议将这种方式作为标准做法,并且仅在您发现需要在构建后期进行优化时才查看其他地方。

于 2012-07-03T16:07:07.783 回答
1

您想要添加一个查找表和一个多对多桥接表。

第三范式通常是好的。为关联的应用程序创建一个表。存储一个引用 ID,它是对您考虑在其中包含此数据的任何其他表的约束。

于 2012-07-03T16:06:29.523 回答
0

为什么不为您的产品表创建一个带有 fk 的产品线表?

于 2012-07-03T16:05:56.113 回答
0

这样做的方法是将零件应用程序存储为单独的行,而不是同一行中的列。

如果表中只有部分应用程序,则只需在行中创建几行而不是几列。

如果表中还有其他数据,请创建另一个表,仅用于将该数据连接到多个部分应用程序。

于 2012-07-03T16:10:50.023 回答