简体   繁体   中英

SQL execution sequence in a transaction

We have a business process for our BI dashboard summary report as below:

  1. SAP writes transaction data to a SQL Server database
  2. SAP triggers a job in SQL Server to populate the summary data based on the transaction data

SAP does this in transaction

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. This leads to the inaccurate summary data.

I added a column with default value getdate() to capture the time on insert.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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