SQL Server - 更新表中的一行时会发生什么? [英] SQL Server - What happens when a row in a table is updated?

查看:25
本文介绍了SQL Server - 更新表中的一行时会发生什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我似乎记得当更新表中的一行时,SQL Server 首先删除该行,然后重新添加该行,如果存在这样的列,则该行具有相同的列的标识值.谁能确认一下?

I seem to recall that when a row in a table is updated, SQL Server first deletes the row, and then re-adds the row, with the same Identity value for a column, if such a column exists. Can anyone confirm this?

推荐答案

False.大多数情况下,数据在同一页面内就地更改.使用 SQL Server 2008,您实际上可以查询数据驻留在磁盘上的位置,这将揭示尽可能多的信息.

现在真正看过它,我收回所有:

Having actually looked at it now, I take it all back:

http://www.sqlskills.com/BLOGS/PAUL/category/On-Disk-Structures.aspx

这可以在 SQL Server 2008 上轻松测试.(从链接文章修改的代码)

This can be easily tested on SQL Server 2008. (code modified from linked article)

CREATE TABLE test (c1 INT, c2 VARCHAR (2000));
GO
CREATE CLUSTERED INDEX test_cl ON test (c1);
GO
CHECKPOINT;
GO
INSERT INTO test VALUES (1, REPLICATE ('Paul', 500));
GO
CHECKPOINT;
select %%physloc%%, * from test    -- 0x3E01000001000000
GO
UPDATE test SET c1 = 2 WHERE c1 =1;
GO
select %%physloc%%, * from test    -- 0x3E01000001000100
                                                     ^
                                                     |
                                    notice it has changed location

这篇关于SQL Server - 更新表中的一行时会发生什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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