简体   繁体   English

创建具有一对多关系的表或仅创建具有单列的表

[英]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.

相关问题 多对多关系 - 将数据从多个表移动到单个表 - Many to many relationships - Moving data from many tables to a single table Mysql 两个表一对多关系与 2 个表与创建其他关系表? - Mysql Two Tables One to many Relationships with 2 tables vs creating other relationship table? 在MySQL中为一对多关系选择表 - Choosing tables for one-to-many relationships in MySQL 对具有一对多关系的3个表进行SQL查询 - SQL query on 3 tables with one to many relationships 创建PostgreSQL表+关系 - 问题与关系 - 一对一 - Creating PostgreSQL tables + relationships - PROBLEMS with relationships - ONE TO ONE 一对多关系:如何返回子表单行的几列? - One-to-many relationships: how to return several columns of a single row of the child table? 将单个映射表用于多个多对多关系 - Using a single mapping table for multiple many-to-many relationships 设计表格时如何实现一对一、一对多和多对多的关系? - How to implement one-to-one, one-to-many and many-to-many relationships while designing tables? 联结表/多对多关系 - junction tables / many to many relationships SQL连接具有一对多关系的多个表而没有“重复” - SQL Join Multiple Tables with One to Many Relationships without “Duplication”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM