[英]Creating tables with one to many relationships or just a table with a single column
If I have multiple key value pairs in Azure Blob Storage such as: 如果我在Azure Blob存储中有多个键值对,例如:
-/files/key1
-/files/key2
-/files/key3
And each key is uploaded by a user, but a user can upload multiple keys, what is the best table design in my SQL database to reference what keys are associated with what user? 每个密钥都是由用户上载的,但是一个用户可以上载多个密钥,我的SQL数据库中最好的表设计是什么,以引用与哪些用户关联的密钥?
A) Table with single column - Everytime I add a file to BLOB storage I add a row to a single column table with the username and the associated key value ie: A)具有单列的表-每次我向BLOB存储中添加文件时,都会向具有用户名和关联键值的单列表中添加一行,即:
AssociationColumn
-User1+key1
-User2+key2
-User1+key3
Will this be slow in looking up all the keys for User1 for example if I query using some sort of regex starts with? 例如,如果我使用某种正则表达式开始查询,查找User1的所有键会很慢吗? Will making this two column with User as one column and key as another column affect performance at all?
将“用户”作为一列而将“键”作为另一列作为两列会完全影响性能吗? How can I achieve this one to many relationship?
我如何实现这种一对多关系?
Also is it bad to store keys using an identifier such as 1-2-n? 使用诸如1-2-n之类的标识符存储密钥是否也很糟糕? Any suggestions on how to create unique identifiers that can fit in the space of varchar(MAX)?
关于如何创建适合varchar(MAX)空间的唯一标识符的任何建议?
The correct approach in a relational database is to have a junction table. 关系数据库中的正确方法是拥有一个联结表。 This would have at least two columns:
这将至少有两列:
User
Key
You wouldn't put these in a single column -- I don't think even in Azure. 您不会将它们放在单个列中-即使在Azure中,我也不认为。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.