更新而不是删除然后在同一张表中插入有什么好处 [英] What is the benefit of update instead of doing delete and then Insert in the same table

查看:101
本文介绍了更新而不是删除然后在同一张表中插入有什么好处的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,例如"ABC"示例,我有一个行需要存储到该"ABC"表中.我计划更新它,而不是从表中删除然后再插入.这将对数据库产生什么影响?在表级别,页面级别,时间,成本和所有方面.

I have a table say example "ABC", I have a row that needs to be stored in to this "ABC" table. I plan to update it instead of doing delete from the table and then insert. What is the impact that this will make on database? In, table level, page level, time, cost and every thing.

推荐答案

我不确定您要问什么,但我会在黑暗中开枪.在表中执行DELETE然后插入INSERT以更新信息是一个非常糟糕的主意.

I'm not 100% certain what you're asking, but I'll take a shot in the dark. Doing a DELETE and then an INSERT into a table to update information is a Very Bad Idea.

为什么?因为如果您有另一个带有外键引用ABC的表,则将丢失您的引用.也就是说,当然,除非您将新记录的PK设置为与旧(已删除)记录的PK相同.在这种情况下,为什么不首先只是更新?

Why? Because if you have another table with a foreign key referencing ABC, you will lose your reference. That is, of course, unless you set the PK of the new record with the same PK as the old (deleted) record. In which case, why didn't you just UPDATE in the first place?

另外,DELETING和INSERTing是两个操作,而UPDATEING是一个操作,这使得(理论上)DELETE和INSERT花费更多的时间.

Additionally, DELETING and then INSERTing is two operations whereas UPDATEing is one, making the DELETE and INSERT take (theoretically) more time.

还有易用性因素.如果先删除然后再插入,则必须手动跟踪每个列的值.如果您进行UPDATE,则只需要知道要更改的内容即可.

There's also the ease-of-use factor. If you DELETE then INSERT, you have to manually keep track of every column value. If you UPDATE, you just need to know what you want to change.

这篇关于更新而不是删除然后在同一张表中插入有什么好处的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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