in src/PDWScripter/PDWscripter.cs [1670:1726]
private void buildCreateTableText(StreamWriter sw)
{
destTableFullName = destTable.Replace(".", "].[");
sourceTmpTableName = "[" + destDb + "].[" + destTableFullName.Replace(destTableFullName.Substring(0, destTableFullName.IndexOf(']')), "DEP") + "]";
if (scriptMode == "Delta")
{
// Copy Data table to Temporary Table
copyDataToTmpTableTxt = "CREATE TABLE " + sourceTmpTableName + "\r\n" +
"WITH ( DISTRIBUTION = " + (distribution_policy == 2 ? ("HASH ([" + distColumn + "])") : (distribution_policy == 3 ? "REPLICATE" : "ROUND_ROBIN")) +
")\r\n" +
"AS SELECT * FROM [" + destDb + "].[" + destTable.Replace(".", "].[") + "]" +
"\r\n;\r\n";
sw.WriteLine(copyDataToTmpTableTxt);
// Drop Table
dropDeployTableTxt = "DROP TABLE [" + destDb + "].[" + destTable.Replace(".", "].[") + "]" +
";\r\n";
sw.WriteLine(dropDeployTableTxt);
}
createTableTxt = "CREATE TABLE [" + destTable.Replace(".", "].[") + "]\r\n(\r\n" +
columnClause + "\r\n)\r\n" +
"WITH ( DISTRIBUTION = " + (distribution_policy == 2 ? ("HASH ([" + distColumn + "])") : (distribution_policy == 3 ? "REPLICATE" : "ROUND_ROBIN")) +
(clusteredClause != "" ? "\r\n, " + clusteredClause : "") +
(partitionBoundaryClause != "" ? ("\r\n, PARTITION ([" + partitionColumn + "] RANGE " + partitionLeftOrRight + " FOR VALUES \r\n(" +
partitionBoundaryClause + ")") : "") +
");\r\n" + nonClusteredClause + statsClause;
sw.WriteLine(createTableTxt);
if (scriptMode == "Delta")
{
// Copy data from Temporary Table
columnSelect = "SET @COLUMNSNAME = NULL \r\n" +
"select @COLUMNSNAME = COALESCE(@COLUMNSNAME,'') + c.name + ', ' " +
"from sys.columns c " +
"where c.object_id = (select object_id from sys.tables where schema_name(schema_id) + '.' + name = '" + destTable + "') \r\n";
sw.WriteLine(columnSelect);
copyDataFromTmpTableTxt = "INSERT INTO [" + destDb + "].[" + destTable.Replace(".", "].[") + "]\r\n(\r\n" +
"@COLUMNSNAME)\r\n " +
"FROM (SELECT @COLUMNSNAME FROM " + sourceTmpTableName + " \r\n " +
";\r\n";
sw.WriteLine(copyDataFromTmpTableTxt);
// Drop Temporary Table
dropDeployTmpTableTxt = "DROP TABLE " + sourceTmpTableName + "\r\n" +
";\r\n";
sw.WriteLine(dropDeployTmpTableTxt);
}
Console.Write(".");
}