[英]Create a copy of partitioned tables using SMO
I'm trying to use SMO to replicate a copy of a partitioned table: 我正在尝试使用SMO复制分区表的副本:
using (var scope = new TransactionScope())
{
var copiedtable = CreateTable(sourcetable);
createColumns(sourcetable, copiedtable);
CreateIndexes(sourcetable, copiedtable);
CreateForeignKeys(sourcetable, copiedtable);
sourcetable.PartitionScheme = sourcetable.PartitionScheme + "1";
scope.Complete();
return copiedtable;
}
The copy is created but the partition scheme is ignored, is there a way to align to the partition scheme? 创建了副本但忽略了分区方案,有没有办法使分区方案对齐? Am I going about things the wrong way? 我会以错误的方式处理事情吗? I receive no error message or exception the code silently creates an unpartitioned copy of the partitioned table. 我没有收到任何错误消息或异常,该代码无提示地创建了分区表的未分区副本。
I want to automate as I have several hundred tables where the partitions are aligned to the wrong schema. 我要自动化,因为我有数百张表,其中分区与错误的架构对齐。
I found a workaround by scripting the definition out into a StringBuilder and then doing a find and replace. 通过将定义脚本编写到StringBuilder中,然后进行查找和替换,我找到了一种解决方法。
var scriptOptions = new ScriptingOptions
{
ClusteredIndexes = true,
Default = true,
FullTextIndexes=true,
Indexes=true,
NonClusteredIndexes = true,
SchemaQualify = true,
DriAllConstraints = true
};
var tableScripts = table.Script(scriptOptions);
String indexName = null;
// Adjust to new table name
sb.Replace(tableName, tableNameNew);
//
sb.Replace(partitionName, partitionName + "_New")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.