UUID与主键的自动递增编号

编程入门 行业动态 更新时间:2024-10-10 08:19:46
本文介绍了UUID与主键的自动递增编号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

为什么我应该为实体的主键选择UUID而不是自动递增号?优点和缺点是什么?

解决方案

安德烈(Andrey)和姆吉(Mjg)都不错,但是我会添加一个重要的性能问题.

通过数据库和密钥生成的分离,还允许对象之间具有复杂关系的应用程序使用适当的密钥来创建它们,从而可以进行大容量插入.

对于自动增量,拥有关系的所有对象(即具有外键的表)必须等待关系的另一端(即外键来自的表)进行保存,查询分配的ID,然后分别更新记录的先前记录.

Why should I choose UUID over an auto increment number for my entity's primary key? What are the pros and cons?

解决方案

Andrey and Mjg both had good points, but I would add a related performance issue that is significant.

With the decoupling of database and key generation also allows applications that have complex relationships between objects to create them all with the keys in place, so that bulk inserts are possible.

In the case of auto-increment, all of the objects that own relationships (ie the tables with foreign keys) have to wait for the other side of the relationship (ie the table the foreign key comes from) to save, query the assigned ids, and then individually update the records former records.

更多推荐

UUID与主键的自动递增编号

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

发布评论

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

>www.elefans.com

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