复合主键限制?

编程入门 行业动态 更新时间:2024-10-28 08:16:24
本文介绍了复合主键限制?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果我从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

更多推荐

复合主键限制?

本文发布于:2023-10-22 23:25:47,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1519038.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:主键

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!