支持我们软件产品的数据库具有如下表设计:
Positions
ID Name Parts
1 One 12345
2 Two 12346
3 Three 12347
Collections
ID TableID Collection
12345 1;1 1;2
12346 1;1 3;4
12347 1;2;2 5;1;2
Parts
ID Name
1 TestOne
2 TestTwo
3 TestThree
4 TestFour
5 TestFive
SubParts
1 SubPartOne
2 SubPartOne
Run Code Online (Sandbox Code Playgroud)
从上面的例子来看,每个Position
都有一个 集合Parts
,但是这些都被一般地(没有外键约束)映射到Collections
表中。该Collections
表跟踪所有对象之间的所有关系,而不仅仅是上面显示的示例表之间的关系,并且将在使用集合的任何时候使用。
这意味着如果我想获得Position
ID 为 1 的及其所有部分。我必须做三个查询:
SELECT * FROM Positions WHERE ID = 1
SELECT * FROM Collections WHERE ID = 12345
Split the string …
Run Code Online (Sandbox Code Playgroud)