在 sql server 表中存储标签的最佳方法? [英] Best way to store tags in a sql server table?

查看:32
本文介绍了在 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 表中存储标签的最佳方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆