我想知道如何同时进行批量插入和批量复制?我有 2 个表应该受到批量复制的影响,因为它们都相互依赖。
所以我想要它,如果在插入表 1 时记录死亡,它会被回滚并且表 2 永远不会更新。此外,如果表 1 插入良好且表 2 更新失败,则表 1 会回滚。
这可以通过批量复制来完成吗?
编辑
我应该提到我正在通过 C# 进行批量插入。
它看起来像这样,但这是我一直在研究的一个例子。所以我不确定是否必须将其更改为存储过程(不确定它的外观以及 C# 代码的外观)
private static void BatchBulkCopy()
{
// Get the DataTable
DataTable dtInsertRows = GetDataTable();
using (SqlBulkCopy sbc = new SqlBulkCopy(connectionString, SqlBulkCopyOptions.KeepIdentity))
{
sbc.DestinationTableName = "TBL_TEST_TEST";
// Number of records to be processed in one go
sbc.BatchSize = 500000;
// Map the Source Column from DataTabel to the Destination Columns in SQL Server 2005 Person Table
// sbc.ColumnMappings.Add("ID", "ID");
sbc.ColumnMappings.Add("NAME", "NAME");
// Number of records after which client has to be notified about its status
sbc.NotifyAfter = dtInsertRows.Rows.Count;
// Event that gets fired when NotifyAfter number of records are processed.
sbc.SqlRowsCopied += new SqlRowsCopiedEventHandler(sbc_SqlRowsCopied);
// Finally write to server
sbc.WriteToServer(dtInsertRows);
sbc.Close();
}
}