如何设计一个可以连接到多个不同表的本地化内容表(关系需要是通用的......)
我知道这并不完全规范化,但是将整个应用程序中的所有本地化数据放入几个表中将会对我有很大帮助。
我必须能够将一些通用表链接到 LocalizedContent 表,该表将包含连接到它的通用表的每个本地化键值对的不同行...我想你可能会说它将是一个 -一对多关系。
我发现的问题是我不确定如何最好地对此进行建模...我可以想到两种方法,但我不确定哪种方法最好:
我的第一个选择是:
AnExampleOfAGenericTable
------------
AnExampleOfAGenericTableID
...other non-localised data...
AnotherGenericTable
------------
AnotherGenericTableID
...other non-localised data...
LocalisedContent
----------------
LocalisedContentID
genericTablePKName
GenericTableID
LanguageID
field
content
在上面可以得到使用如下 SQL 查询为通用表输出本地化内容:
SELECT AnExampleOfAGenericTableID, field, content
FROM AnExampleOfAGenericTable LEFT JOIN LocalisedContent
ON AnExampleOfAGenericTable.AnExampleOfAGenericTableID =
LocalisedContent.GenericTableID
WHERE genericTablePKName = 'AnExampleOfAGenericTableID'
或者:
SELECT AnotherGenericTableID, field, content
FROM AnotherGenericTable LEFT JOIN LocalisedContent
ON AnotherGenericTable.AnotherGenericTableID = LocalisedContent.GenericTableID
WHERE genericTablePKName = 'AnotherGenericTableID'
第二个选项似乎是:
AnExampleOfAGenericTable
------------
AnExampleOfAGenericTableID
...other non-localised data...
localisedGroupID
AnotherGenericTable
------------
AnotherGenericTableID
...other non-localised data...
localisedGroupID
LocalisedContent
----------------
LocalisedContentID
localisedGroupID
LanguageID
field
content
然后我可以使用如下 SQL 查询:
SELECT AnExampleOfAGenericTableID, field, content
FROM AnExampleOfAGenericTable LEFT JOIN LocalisedContent
ON AnExampleOfAGenericTable.localisedGroupID = LocalisedContent.localisedGroupID;
或者:
SELECT AnotherGenericTableID, field, content
FROM AnotherGenericTable LEFT JOIN LocalisedContent
ON AnotherGenericTable.localisedGroupID = LocalisedContent.localisedGroupID;
第二个选项对我来说似乎更简洁,但它确实需要我加入了两个FK,这似乎有点奇怪。它还需要大量额外的“localizedGroupID”列。
最终,我给出的两个例子都可能是错误的,而且我没有专业知识来知道最好的解决方案。 (在您指出这还没有完全规范化之前,我已经说过我不希望每个表都有数百个不同的本地化数据表......我确实希望对本地化进行一定程度的集中化,即使它会让我失去一点参考完整性。)
想法?
I know that this isn't exactly normalised, but bringing all of the localised data throughout my application into just a few tables will help me out a lot.
I have to be able to link some generic table to a LocalisedContent table which will contain different rows for each of the localised key-value pairs of the generic table joined to it... I guess you could say that it will be a one-to-many relationship.
The problem I've found is that I am not sure how to best model this... I can think of two ways and I am not sure which one is best:
My first option is:
AnExampleOfAGenericTable
------------
AnExampleOfAGenericTableID
...other non-localised data...
AnotherGenericTable
------------
AnotherGenericTableID
...other non-localised data...
LocalisedContent
----------------
LocalisedContentID
genericTablePKName
GenericTableID
LanguageID
field
content
In the above it would be possible to get out localised content for a generic table with an SQL query like:
SELECT AnExampleOfAGenericTableID, field, content
FROM AnExampleOfAGenericTable LEFT JOIN LocalisedContent
ON AnExampleOfAGenericTable.AnExampleOfAGenericTableID =
LocalisedContent.GenericTableID
WHERE genericTablePKName = 'AnExampleOfAGenericTableID'
Or:
SELECT AnotherGenericTableID, field, content
FROM AnotherGenericTable LEFT JOIN LocalisedContent
ON AnotherGenericTable.AnotherGenericTableID = LocalisedContent.GenericTableID
WHERE genericTablePKName = 'AnotherGenericTableID'
The second option seems to be, something like:
AnExampleOfAGenericTable
------------
AnExampleOfAGenericTableID
...other non-localised data...
localisedGroupID
AnotherGenericTable
------------
AnotherGenericTableID
...other non-localised data...
localisedGroupID
LocalisedContent
----------------
LocalisedContentID
localisedGroupID
LanguageID
field
content
And then I could use an SQL query like:
SELECT AnExampleOfAGenericTableID, field, content
FROM AnExampleOfAGenericTable LEFT JOIN LocalisedContent
ON AnExampleOfAGenericTable.localisedGroupID = LocalisedContent.localisedGroupID;
Or:
SELECT AnotherGenericTableID, field, content
FROM AnotherGenericTable LEFT JOIN LocalisedContent
ON AnotherGenericTable.localisedGroupID = LocalisedContent.localisedGroupID;
The second option seems more concise to me, but it does require me to join two FKs which seems a little strange. It also requires a lot of extra 'localisedGroupID' columns.
Ultimately both of the examples I've given may be wrong and I don't have the expertise to know the best solution to this. (Before you point out that this isn't fully normalised, I've already said I don't want hundreds of different localised data tables for each of my tables... I do want some amount of centralisation to the localisation even if it will lose me a little referential integrity.)
Ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的模式让我想起了网络上提供的“泛化专业化关系建模”示例,其中有一个重要的区别。
您所说的 AnExampleOfAGenericTable 和 AnotherGenericTable 对应于 gen-spec 模式中的专用表,您所说的 LocalizedContent 对应于 gen-spec 模式中的通用表。
如果我理解正确,前两个表中的每个条目都将在 LocalizedContent 表中具有对应项,但 LocalizedContent 表中的条目将仅在其他两个表之一中具有对应项。这与 gen-spec 的模式完全相同,只是向后。
在gen-spec设计中,您在通用表中使用的所有专用表中使用相同的PK。然而,专用表中的PK也是通用表中的FK。当然,您只使用 gen 表中的自动编号功能。
gen-spec 本身并没有什么不规范的地方。
Your schema remninds me of the "generalization specialization relational modeling" examples available on the web, with one important difference.
What you're calling AnExampleOfAGenericTable and AnotherGenericTable correspond to the specialized tables in the gen-spec pattern, and what you're calling LocalisedContent corresponds to the generalized table in the gen-spec pattern.
If I've understood you right every entry in the first two tables is going to have a counterpart in the LocalisedContent table, but an entry in the LocalisedContent table is going to have a counterpart in only one of the other two tables. That's exactly the same pattern as gen-spec, only backwards.
In gen-spec design, you use the same PK in all the specialized tables that you use in the generalized table. However, the PK in a specialized table is also an FK to the generalized table. And, of course, you only use the autonumber feature in the gen table.
There's nothing unnormalized about gen-spec as such.
我们使用以下内容:
LocalizedContent:
其中关键格式为“TableName.ColumnName”
用法:
GenericTable 为(Id、Name、Description)
We use the following:
LocalizedContent:
Where key in format 'TableName.ColumnName'
usage:
GenericTable is (Id, Name, Description)