【发布时间】:2015-10-04 08:24:40
【问题描述】:
我有 1 个核心 SQL Server 和许多将数据传输到核心服务器的辅助 SQL Server。
每个辅助 SQL Server 都有链接的核心服务器和不时运行的存储过程。
这是来自存储过程的代码(删除了一些字段,但并不重要)
BEGIN DISTRIBUTED TRANSACTION
SELECT TOP (@ReceiptsQuantity)
MarketId, CashCheckoutId, ReceiptId, GlobalReceiptId
INTO #Receipts
FROM dbo.Receipt
WHERE Transmitted = 0
SELECT ReceiptId, Barcode, GoodId
INTO #ReceiptGoodsStrings
FROM ReceiptGoodsStrings
WHERE ReceiptGoodsStrings.ReceiptId in (SELECT ReceiptId FROM #Receipts)
INSERT INTO [SyncServer].[POSServer].[dbo].[Receipt]
SELECT * FROM #Receipts
INSERT INTO [SyncServer].[POSServer].[dbo].[ReceiptGoodsStrings]
SELECT * FROM #ReceiptGoodsStrings
UPDATE Receipt
SET Transmitted = 1
WHERE ReceiptId in (SELECT ReceiptId FROM #Receipts)
DROP TABLE #Receipts
DROP TABLE #ReceiptGoodsStrings
COMMIT TRANSACTION
有两个表:Receipts有很多ReceiptGoodsStrings(键ReceiptID)
一切正常。但有时在核心服务器上,我在Receipts 和ReceiptGoodsStrings 中重复了行。这种情况很少发生,我不明白为什么。
也许我选择了错误的数据传输方式?
【问题讨论】:
标签: sql sql-server tsql transactions distributed-transactions