对标签名使用主键还是唯一索引?

时间:2022-08-15 18:51:48

I'm just wondering that, if I implemented a tags system, should I use a primary key on the tag name, or just have the usual primary key with a unique index on the tag name column?

我只是想知道,如果我实现了一个标记系统,我是应该在标记名上使用主键,还是应该在标记名列上使用具有惟一索引的通常主键?

2 个解决方案

#1


5  

Assuming the tag entity will be used in millions of rows, a numeric column will perform better than a string as a foreign key column. This is why you use surrogate keys

假设标记实体将在数百万行中使用,数字列将比字符串作为外键列执行得更好。这就是为什么要使用代理键

So "just have the usual primary key with a unique index on the tag name column"

所以"只需要在标签名列上有唯一索引的主键"

#2


1  

If you have two keys in a table then it makes no difference which one you make the "primary" key. What matters is how you intend to use them.

如果你在一个表中有两个键,那么你做的“主”键是没有区别的。重要的是您打算如何使用它们。

#1


5  

Assuming the tag entity will be used in millions of rows, a numeric column will perform better than a string as a foreign key column. This is why you use surrogate keys

假设标记实体将在数百万行中使用,数字列将比字符串作为外键列执行得更好。这就是为什么要使用代理键

So "just have the usual primary key with a unique index on the tag name column"

所以"只需要在标签名列上有唯一索引的主键"

#2


1  

If you have two keys in a table then it makes no difference which one you make the "primary" key. What matters is how you intend to use them.

如果你在一个表中有两个键,那么你做的“主”键是没有区别的。重要的是您打算如何使用它们。