欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

mysql 主键唯一,MySQL。关键表中的主键。唯一ID还是多个唯一键?

发布时间:2025/3/11 26 豆豆
生活随笔 收集整理的这篇文章主要介绍了 mysql 主键唯一,MySQL。关键表中的主键。唯一ID还是多个唯一键? 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

Primary key in relational tables. Composite primary key or unique primary key in those pure relational tables?

Which design would you recommend to use in MySQL for high performance? See diagram

Technical advantages and disadvantages!

Thanks everyone!

解决方案

It really depends on the type of query you're doing...

If you add an extra surrogate, you'll end up doing two unique checks instead of a single one for every insert, update and delete. That makes the composite key sound right.

But if you're constantly referencing that primary key in other foreign keys, the composite option means you end up storing twice as much information and need to do more work when joining. That makes the single key sound right.

创作挑战赛新人创作奖励来咯,坚持创作打卡瓜分现金大奖

总结

以上是生活随笔为你收集整理的mysql 主键唯一,MySQL。关键表中的主键。唯一ID还是多个唯一键?的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。