Fixes generating data script

This commit is contained in:
2017-01-31 16:25:20 +01:00
parent 0e9d204a8a
commit 59d351d14f
2 changed files with 29 additions and 12 deletions

View File

@@ -286,6 +286,7 @@
// //
// btnExportData // btnExportData
// //
this.btnExportData.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btnExportData.Location = new System.Drawing.Point(84, 485); this.btnExportData.Location = new System.Drawing.Point(84, 485);
this.btnExportData.Name = "btnExportData"; this.btnExportData.Name = "btnExportData";
this.btnExportData.Size = new System.Drawing.Size(75, 23); this.btnExportData.Size = new System.Drawing.Size(75, 23);

View File

@@ -291,28 +291,43 @@ namespace ServerExplorer.UI
listCmds.Add("SET NOCOUNT ON;"); listCmds.Add("SET NOCOUNT ON;");
listCmds.Add(string.Empty); listCmds.Add(string.Empty);
// Comandos de desactivacion de FKs //// Comandos de desactivacion de FKs
foreach (TablaDesc t in db.Tablas) //foreach (TablaDesc t in db.Tablas)
{ //{
string tableName = string.Format("{0}.{1}", t.Esquema, t.Nombre); // string tableName = string.Format("{0}.{1}", t.Esquema, t.Nombre);
listCmds.Add(string.Format("ALTER TABLE {0} NOCHECK CONSTRAINT all;", tableName)); // listCmds.Add(string.Format("ALTER TABLE {0} NOCHECK CONSTRAINT all;", tableName));
} //}
//listCmds.Add("GO");
//listCmds.Add(string.Empty);
// Desactivar todas las FKs
listCmds.Add("-- Disable all constraints");
listCmds.Add("EXEC sp_MSforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT all'");
listCmds.Add("GO");
listCmds.Add(string.Empty); listCmds.Add(string.Empty);
// Prepara informacion a exportar // Prepara informacion a exportar
foreach (TablaDesc t in db.Tablas) foreach (TablaDesc t in db.Tablas)
{ {
string tableName = string.Format("{0}.{1}", t.Esquema, t.Nombre); string tableName = string.Format("{0}.{1}", t.Esquema, t.Nombre);
listCmds.Add(string.Format("PRINT '*** Importing data of {0}....';", tableName));
List<string> listCmdsTableData = ExportData(tableName); List<string> listCmdsTableData = ExportData(tableName);
listCmds.AddRange(listCmdsTableData); listCmds.AddRange(listCmdsTableData);
} }
// Comandos de activacion de FKs //// Comandos de activacion de FKs
foreach (TablaDesc t in db.Tablas) //foreach (TablaDesc t in db.Tablas)
{ //{
string tableName = string.Format("{0}.{1}", t.Esquema, t.Nombre); // string tableName = string.Format("{0}.{1}", t.Esquema, t.Nombre);
listCmds.Add(string.Format("ALTER TABLE {0} WITH CHECK CHECK CONSTRAINT all;", tableName)); // listCmds.Add(string.Format("ALTER TABLE {0} WITH CHECK CHECK CONSTRAINT all;", tableName));
} //}
//listCmds.Add("GO");
//listCmds.Add(string.Empty);
// Activar todas las FKs
listCmds.Add("-- Enable all constraints");
listCmds.Add("EXEC sp_MSforeachtable @command1='print ''?''', @command2='ALTER TABLE ? WITH CHECK CHECK CONSTRAINT all'");
listCmds.Add("GO");
listCmds.Add(string.Empty); listCmds.Add(string.Empty);
// Escribir script // Escribir script
@@ -341,6 +356,7 @@ namespace ServerExplorer.UI
listCmds.Add(string.Format("SET IDENTITY_INSERT {0} ON;", tableName)); listCmds.Add(string.Format("SET IDENTITY_INSERT {0} ON;", tableName));
listCmds.AddRange(listCmdsInsert); listCmds.AddRange(listCmdsInsert);
listCmds.Add(string.Format("SET IDENTITY_INSERT {0} OFF;", tableName)); listCmds.Add(string.Format("SET IDENTITY_INSERT {0} OFF;", tableName));
listCmds.Add("GO");
listCmds.Add(string.Empty); listCmds.Add(string.Empty);
return listCmds; return listCmds;