Best way to store tags in a sql server table?(将标签存储在 sql server 表中的最佳方法?)
问题描述
为记录存储标签的最佳方式是什么?只使用 varchar 字段?选择包含标签 x 的行时怎么办?使用like运算符?
What's the best way to store tags for a record? Just use a varchar field? What about when selecting rows that contains tag x? Use the like operator?
谢谢!
推荐答案
取决于两件事:
1)标签/标签记录的数量
2) 你是否对规范化有宗教观点:-)
Depends on two things:
1) The amount of tags/tagged records
2) Whether or not you have a religious opinion on normalization :-)
除非处理大量数据,否则我建议有一个标签"表,将 varchar 值映射到整数标识符,然后第二个表将标记记录映射到它们的标签 ID.我建议先实现它,然后检查它是否不满足您的性能需求.在这种情况下,为标记的行和标记的实际文本保留一个带有 id 的表,但是在这种情况下,我建议您使用 char 列,因为如果优化器执行全表扫描,它将终止您的查询带有 varchar 列的大表.
Unless dealing with very large volumes of data, I'd suggest having a 'Tags' table mapping varchar values to integer identifiers then second table mapping tagged records to their tag ids. I'd suggest implementing this first, then check if it doesn't meet your performance needs. In that case, keep a single table with a id for the tagged row and the actual text of the tag, but in this I'd suggest you use a char column as it will kill your query if the optimizer does a full table scan against a large table with a varchar column.
这篇关于将标签存储在 sql server 表中的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:将标签存储在 sql server 表中的最佳方法?
基础教程推荐
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- 无法解决整理冲突 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
