我正在编写一个脚本来将数据从一个数据库服务器移动到另一个数据库服务器。一次一张 table 对我来说有好处。我已经删除了所有外键等。
我正在遵循这个例子。
http://fsharpforfunandprofit.com/posts/low-risk-ways-to-use-fsharp-at-work-4/#sql-etl
问题是我不想转换数据,我只想复制它。但我有很多表,每个表都有很多列。在不映射每个单独字段的情况下从一个记录映射到另一个记录的简单方法是什么?
最佳答案
您可以稍微修改@Petr引用的脚本来复制指定的表而不是所有表。请参阅下面的示例。
// Start of modifications here
// Create an array of objects in this case tables to copy
let tablesToCopy =
sourceDatabase.Tables
|> Seq.cast<Table> // Convert TableCollection to seq<Table> so can use Seq functions
|> Seq.filter (fun table -> [| "DimTime"; "DimCategory" |] |> Seq.exists (fun tableName -> tableName = table.Name))
|> Seq.toArray // Materialise to an Array so it can be consumed by an ArrayList constructor and assigned to the ObjectList property
let transferDatabase =
Transfer(sourceDatabase,
CopyAllObjects = false, // Set to false
CopyAllSchemas = true,
CopyAllUserDefinedDataTypes = true,
CopyAllTables = false, // Set to false
ObjectList = System.Collections.ArrayList(tablesToCopy), // Include a list of objects to copy - uses old style ArrayList
CopyData = true,
CopyAllStoredProcedures = true,
DestinationServer = destServer.Name,
DestinationDatabase = destDatabase.Name)
// End of modifications here
关于f# 克隆记录数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35293520/