11# SQL Bulk Copy & Merge
22
3- This library aims to make copying table data between SQL databases easier .
3+ This library aims to make easier and more efficient specific workflows in .NET that copy table data between SQL databases.
44
55SQLBulkCopy is useful to copy between databases, but truncating the destination table each time before copying is not always possible or efficient.
6- An alternative is to use SQLBulkCopy to copy to a temporary table and then run SQL MERGE between the temporary table and target.
7- Some other solutions that do this require extra work defining the table schemas or are dependant on a stored proc.
6+ An alternative workflow is to use SQLBulkCopy to copy to a temporary table and then run SQL MERGE between the temporary table and target.
7+ Some other solutions that do this require extra work defining the table schemas or are dependant on a SQL stored proc.
88
99This .NET library has the following methods:
1010
@@ -22,7 +22,7 @@ The specific steps it performs:
2222### Usage:
2323```
2424var copyService = new SqlBulkCopyMergeService(sourceDbConnectionString, targetDbConnectionString);
25- var result = await copyService.CopyAndMerge(sourceTable , targetTable);
25+ var result = await copyService.CopyAndMerge(sourceTableOrView , targetTable);
2626Console.WriteLine("Rows Inserted: " + result.Inserted);
2727Console.WriteLine("Rows Updated: " + result.Updated);
2828Console.WriteLine("Rows Deleted: " + result.Deleted);
@@ -35,7 +35,7 @@ var columnMappings = new List<ColumnMapping>
3535 new ColumnMapping("id", "code"),
3636 new ColumnMapping("notes", "description")
3737};
38- var result = await copyService.CopyAndMerge(sourceTable , targetTable, columnMappings);
38+ var result = await copyService.CopyAndMerge(sourceTableOrView , targetTable, columnMappings);
3939```
4040
4141## CopyLatest
@@ -52,7 +52,7 @@ The result of the source query is directly copied into the target table using SQ
5252### Usage:
5353```
5454var copyService = new SqlBulkCopyMergeService(sourceDbConnectionString, targetDbConnectionString);
55- var result = await copyService.CopyLatest(sourceTable , targetTable, keyColumnName);
55+ var result = await copyService.CopyLatest(sourceTableOrView , targetTable, keyColumnName);
5656Console.WriteLine("Rows Copied: " + result.RowsCopied);
5757```
5858
0 commit comments