gpt4 book ai didi

sql - 数据库表损坏,查询无效 : what has it done and will it roll back?

转载 作者:行者123 更新时间:2023-12-03 01:57:35 25 4
gpt4 key购买 nike

我在运行本应对我的事实表(2 亿行)进行快速更新时犯了错误:

update dbo.primary_fact
set count_of_loan_obligors = o.n
from dbo.staging_fact f
-- notice that this is not the same table as the one in the update clause
inner join ##Obligor_Count o
on (f.time_dimension_id = o.time_dimension_id
and f.account_dimension_id = o.account_dimension_id)

应该是:

  from dbo.primary_fact f

像这样正确形成的更新(1 天,87k 个帐户)通常会在一到 2 分钟内完成。运行 12 分钟后,我想知道是什么花了这么长时间,并发现了我的错误。

我取消了 SQL Server Management Studio 中的查询,我知道这将回滚我造成的所有糟糕情况(有人可以确认吗?)

但我更大的问题是:格式不正确的查询会做什么?

<小时/>

更新:取消操作终于在 1 小时 39 分钟后完成。 DBA 的杀戮速度太慢了——这也没什么不好。

格式正确的更新在 8 秒内完成。

第二次更新:在 SSMS 中成功取消订单后,原始(错误)更新中没有设置任何值。我认为这意味着任何待处理的更新都被回滚。

最佳答案

But my bigger question is: What does the incorrectly formed query do?

它将用相同的值更新所有行的 dbo.primary_fact.count_of_loan_obligors。该值将是 ##Obligor_Count.n 中的某个值。很难弄清楚那会有什么值(value)。

这里有一个小测试,基本上可以完成您所做的事情:

declare @T1 table (ID int)
declare @T2 table (ID int)

insert into @T1 values (0)
insert into @T1 values (0)

insert into @T2 values (2)
insert into @T2 values (1)

update @T1
set ID = T2.ID
from @T2 as T2

select *
from @T1

结果:

ID
2
2

在本例中,@T1 将更新为 @T2 中的第一行。

关于sql - 数据库表损坏,查询无效 : what has it done and will it roll back?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6364780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com