如何将构词规范化地存储在关系数据库中?
我正在尝试找到一种存储以下形式的单词组合的好方法:
exhaustcleaningsystem exhaust cleaning system exhaustcleaning system exhaust cleaningsystem
组合按每种情况默认给出。组合中的每个单词都作为唯一的行存储在表“标签”中。
labels id value -------------------------- 1 exhaustcleaningsystem 2 exhaust 3 cleaning 4 system 5 exhaustcleaning 6 cleaningsystem
我考虑了一个名为“组合”的新表:
compositions id domain_id range ---------------------- 1 1 2,3,4 2 1 5,4 etc...
但是在列中存储多个分隔值并不是标准化设计。有什么想法吗?
顺便说一句:我正在使用 MySQL 和 ActiveRecord/Rails。
I'm trying to find a nice way to store word compositions of the following form:
exhaustcleaningsystem exhaust cleaning system exhaustcleaning system exhaust cleaningsystem
The combinations are given by a default per case. Every word in a composition is stored as a unique row in table 'labels'.
labels id value -------------------------- 1 exhaustcleaningsystem 2 exhaust 3 cleaning 4 system 5 exhaustcleaning 6 cleaningsystem
I thought about a new table called 'compositions':
compositions id domain_id range ---------------------- 1 1 2,3,4 2 1 5,4 etc...
But storing multiple separated values in a column isn't normalized design. Any ideas for that?
BTW: I'm using MySQL und ActiveRecord/Rails.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您提出的设计甚至不是第一范式,因为范围不是原子的
我在这里使用的模式将是
与composition_id引用composition.id和label_id引用label.id
排名列是可选的,应该在这里如果和仅当您在此处定义的范围对顺序敏感时。
通过这种设计,您可以在数据库级别获得一些引用完整性。
The design you propose is not even in first normal form, since range is not atomic
The schema I'd use here would be
with composition_id referencing an composition.id and label_id referencing label.id
The rank column is optional and should be here if and only if the range you define here is order-sensitive.
With this design, you have some referential integrity at DB level.
嗯,这是我在标准化方面所能想到的:
Well, this is as far as I can think of in terms of normalisation: