主键更新与主键删除+插入 [英] primary key update vs primary key deletion + insertion

查看:80
本文介绍了主键更新与主键删除+插入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我听说有传言说,当更改主键列中的值时,应先删除行,然后再插入新值,而不要更新列.

I have heard some rumours that when value in primary key column is changed, then row should be deleted then inserted with new value rather then column just updated.

更新主键而不删除/插入主键是否会对性能产生影响?

Are there any performance implications when primary key is updated and not deleted/inserted?

推荐答案

更新主键时:

  • 支持索引已更新.
  • 是否为外键将被检查 给孩子们.
  • the supporting index is updated.
  • if it is a foreign key will be checked for childs.

但是,如果您执行删除和插入操作,则删除操作将同时执行两个操作,插入操作将更新索引.因此,进行删除和插入没有任何好处.还是我所不知道的.

But if you do a delete and an insert, for delete both points are performed and for insert the index is updated. So no gain to do a delete and an insert. Or none that I'm aware of.

很快,执行两次操作而不是一次操作会更糟.不算删除是最难的操作.

Shortly, it is worse to do two operations instead of one. Not counting that delete is the hardest operation.

这篇关于主键更新与主键删除+插入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆