You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-Added new explicit CopyTableDataAsync() APIs which enable explicit copying of data between two tables on matching columns (automatically detected by Name and Data Type).
-Added new Materialized Data Configuration value MaterializedDataLoadingTableDataCopyMode to control whether the materialized data process automatically copies data into the Loading Tables after cloning. This helps to greatly simplify new use cases where data must be merged (and preserved) during the materialization process.
////TODO: Might (potentially if it doesn't impede performance too much) implement support for re-mapping FKey constraints to Materialization Context tables so data integrity issues will be caught sooner
//If both Source & Target are the same (e.g. Target was not explicitly specified) then we adjust
399
+
// the Target to ensure we create a copy and append a unique Copy Id...
400
+
if(targetTable.EqualsIgnoreCase(sourceTable))
401
+
thrownewInvalidOperationException($"The source table name {sourceTable.FullyQualifiedTableName} and target table name {targetTable.FullyQualifiedTableName} must be different.");
//In this overload we handle the Source Table Definition and can dynamically determine if there is An Identity column we handle by enabling insertion for them...
117
-
if(hasIdentityColumn)
118
-
{
119
-
ScriptBuilder.Append($@"
120
-
--The Table {sourceTableDefinition.TableFullyQualifiedName} has an Identity Column {sourceTableDefinition.IdentityColumn.ColumnName.QualifySqlTerm()} so we must allow Insertion of IDENTITY values to copy raw table data...
121
-
SET IDENTITY_INSERT {targetTable.FullyQualifiedTableName} ON;
thrownewArgumentException("There are no matching column definitions between the source & target table schema definitions provided; there must be at least one column matching on name & data type.");
127
122
128
-
//In this overload we handle the Source Table Definition and can dynamically determine if there is An Identity column we handle by enabling insertion for them...
129
-
if(hasIdentityColumn)
130
-
{
131
-
ScriptBuilder.Append($@"
132
-
--We now disable IDENTITY Inserts once all data is copied into {targetTable}...
133
-
SET IDENTITY_INSERT {targetTable.FullyQualifiedTableName} OFF;
134
-
");
135
-
}
123
+
//Now we can Copy data between the two tables on the matching columns detected and enable Identity Insert if the
124
+
// Target has an Identity Column which might be explicitly copied...
//In this overload we handle the Source Table Definition and can dynamically determine if there is An Identity column we handle by enabling insertion for them...
163
+
if(enableIdentityInsertOnTarget)
164
+
{
165
+
ScriptBuilder.Append($@"
166
+
--The Table {targetTable.FullyQualifiedTableName} has an Identity Column so we must allow Insertion of IDENTITY values to copy raw table data...
167
+
SET IDENTITY_INSERT {targetTable.FullyQualifiedTableName} ON;
168
+
");
169
+
}
170
+
151
171
ScriptBuilder.Append($@"
152
172
--Syncs the Identity Seed value of the Target Table with the current value of the Source Table (captured into Variable at top of script)
153
173
INSERT INTO {targetTable.FullyQualifiedTableName} ({columnNamesCsv})
154
174
SELECT {columnNamesCsv}
155
175
FROM {sourceTable.FullyQualifiedTableName};
156
176
");
177
+
178
+
//In this overload we handle the Source Table Definition and can dynamically determine if there is An Identity column we handle by enabling insertion for them...
179
+
if(enableIdentityInsertOnTarget)
180
+
{
181
+
ScriptBuilder.Append($@"
182
+
--We now disable IDENTITY Inserts once all data is copied into {targetTable.FullyQualifiedTableName}...
183
+
SET IDENTITY_INSERT {targetTable.FullyQualifiedTableName} OFF;
0 commit comments