简体   繁体   English

事务中的SQL执行序列

[英]SQL execution sequence in a transaction

We have a business process for our BI dashboard summary report as below: 我们的BI仪表板摘要报告具有以下业务流程:

  1. SAP writes transaction data to a SQL Server database SAP将事务数据写入SQL Server数据库
  2. SAP triggers a job in SQL Server to populate the summary data based on the transaction data SAP触发SQL Server中的作业以基于事务数据填充摘要数据

SAP does this in transaction SAP在交易中做到这一点

BEGIN TRAN
    Prepare INSERT statements to STOCK_SALES_VARIANT (2000 records)
    Prepare INSERT statements to STOCK_SALES_BUYER (16000 records)
    CALL JOB "Batch Insert"
    CALL JOB "Populate Summary"
COMMIT

We found that the job "Populate Summary" has been called before the STOCK_SALES_BUYER data insert completed. 我们发现在完成STOCK_SALES_BUYER数据插入之前已调用作业“填充摘要”。 This leads to the inaccurate summary data. 这导致摘要数据不正确。

I added a column with default value getdate() to capture the time on insert. 我添加了一个默认值为getdate()的列,以捕获插入时间。

Here is the log: 这是日志:

Variant table - 2016-02-05 10:41:08.547 to 2016-02-05 10:41:09.817
Buyer table - 2016-02-05 10:41:11.477     2016-02-05 10:41:15.480
Job - 2016-02-05 10:41:12 to 2016-02-05 10:41:21

I can see the job started before the last record written in buyer table. 我可以看到作业在买方表中写入最后一条记录之前开始。

Can someone advise how to resolve this timing issue and explain how multiple statements run in sequence behind the scene? 有人可以建议如何解决此时序问题,并解释如何在后台按顺序运行多个语句吗? Thank you! 谢谢!

Identify the issue is that the second job starts before the first job finish inside a stored procedure. 确定问题是在存储过程中第二个作业在第一个作业完成之前开始。 I did some more research and found that this is a nature design for a stored procedure. 我进行了更多研究,发现这是存储过程的自然设计。 Adding a delay timer in the second job helps fix the issue. 在第二项工作中添加延迟计时器有助于解决此问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM