如何提高这个DML语句的性能?
你好 该语句在存储过程中执行。我正在传递参数,它正在执行多次更新和插入。 我将不胜感激一些建议 - 提高性能, - 减少执行时间 - 以及代码结构的改进。 存在三个不同的表:Table_01、Table_02、Table_03。
INSERT INTO Table_01(
TestID,
TestData,
CurrentDate,
UserID,
Status
) VALUES (
@testID,
@testData,
@iDateTime,
@userID,
@Status
)
IF (@Status = 1)
BEGIN
DELETE FROM
Table_02
WHERE
TestID = @testID
UPDATE Table_03
SET
Status = 1,
Date = @iDateTime,
Work = 0
WHERE
TestID = @testID
END
Hi
This statements are executed in Stored Procedure. I am passing parameters and It is doing multiple updates and inserts.
I will appreciate some suggestions to
-improve the performance,
-reduce the execution time
-and improvements in code structure.
There are three different tables: Table_01, Table_02, Table_03.
INSERT INTO Table_01(
TestID,
TestData,
CurrentDate,
UserID,
Status
) VALUES (
@testID,
@testData,
@iDateTime,
@userID,
@Status
)
IF (@Status = 1)
BEGIN
DELETE FROM
Table_02
WHERE
TestID = @testID
UPDATE Table_03
SET
Status = 1,
Date = @iDateTime,
Work = 0
WHERE
TestID = @testID
END
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
说实话,不需要太多调整:它是简单的代码,没什么花哨的。
您可以添加一个事务,以便所有写入都成功或所有写入失败。
如果您发现代码很慢,那么我会查看 TestID 上的索引,看看您是否有触发器
Not really much to tweak to be honest: it's straightforward code, nothing fancy
You can add a transaction so it all writes succeed or all writes fail.
If you find the code slow then I'd look at indexes on TestID and do you have triggers