本文介绍了复合主键限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果我从4列创建复合主键,可以吗?喜欢:
Is it OK if I create a composite primary key from 4 columns? Like:
PRIMARY KEY(name, slug, type, parent)
所以不应该有多个具有相同名称,slug,type和parent的行。列太多了吗?它会影响性能吗?
So there should not be more than one row with the same name, slug, type and parent. Are there too many columns? Will it affect performance?
我正在使用sqlite btw。
I'm using sqlite btw.
推荐答案
通常建议使用一个独有的ID字段。比较INTEGER值比比较字符串更快,因此复合键会对性能产生负面影响。
It's usually recommended to have an ID field that is unique on its own. Comparing INTEGER values is faster than comparing strings, so your composite key will affect performance negatively.
如果要加入,添加具有以下数据类型的列将是理想的到其他表格:
Adding a column with the following as the datatype would be ideal if you will be joining to other tables:
INTEGER PRIMARY KEY AUTOINCREMENT
这篇关于复合主键限制?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!