如何在SQL Server中快速停止插入语句流程
我有一个插入声明,该声明应该插入500K记录,但是2小时后,只插入了100K。
我决定取消该过程,现在可以看到插入的记录数量非常缓慢。
基于这将需要一天才能撤消那些插入的行。
有没有办法停止它并接受已插入或截断该表的所有内容并停止“取消查询”过程?
insert into xT2 (a_i, b_i, a_icd, b_icd, a_code, b_code, a_spcode, b_spcode, a_forcode, b_forcode, distance)
select
a.i a_i,
b.i b_i,
a.icd a_icd,
b.icd b_icd,
a.code a_code,
b.code b_code,
a.spcode a_spcode,
b.spcode b_spcode,
a.forcode a_forcode,
b.forcode b_forcode, -99 Distance
from
xT1 A
inner join
xT1 B on a.i < b.i
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
除了上面的肖恩·兰格(Sean Lange)的评论外,您不能接受部分插入物,该插件由于酸特性中的原子性而被插入。
原子性意味着您保证所有交易都成功或无能为力。您不会获得成功的一部分,也没有一部分。如果交易的一部分失败,则整个交易失败。具有原子性,它是“全部或全无”。我从简洁的。如果您还没有这样做,请阅读其他属性,因为它们非常基本了解DBMS的工作原理。
顺便说一句,500k行是相对较少的行,不应花费近2个小时的时间来插入,您的AI列中是否有零值,或者在查询正在运行时系统上的负载很重?只是为了添加另一个可能的项目,AI是否索引?
Further to Sean Lange's comment above, you cannot accept a partial insert which has been inserted due to the A for Atomicity in the ACID properties.
Atomicity means that you guarantee that either all of the transaction succeeds or none of it does. You don’t get part of it succeeding and part of it not. If one part of the transaction fails, the whole transaction fails. With atomicity, it's either "all or nothing". I took this description from https://database.guide/what-is-acid-in-databases/ as it describes is concisely. If you have not done so already, read up on the other properties as they are very fundamental in understanding how a DBMS works.
As an aside, 500K rows is a relatively small amount of rows and should not take anywhere near 2 hours to insert, are there any NULLS in your a.i column or is there a very heavy load on the system at the time the query is running? Just to add another possible item, is a.i indexed?