diff --git a/ServerExplorer/UI/FrmBaseDatos.Designer.cs b/ServerExplorer/UI/FrmBaseDatos.Designer.cs index 06a7a3b..1f58b91 100644 --- a/ServerExplorer/UI/FrmBaseDatos.Designer.cs +++ b/ServerExplorer/UI/FrmBaseDatos.Designer.cs @@ -286,6 +286,7 @@ // // 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.Name = "btnExportData"; this.btnExportData.Size = new System.Drawing.Size(75, 23); diff --git a/ServerExplorer/UI/FrmBaseDatos.cs b/ServerExplorer/UI/FrmBaseDatos.cs index 94a940b..4846644 100644 --- a/ServerExplorer/UI/FrmBaseDatos.cs +++ b/ServerExplorer/UI/FrmBaseDatos.cs @@ -291,28 +291,43 @@ namespace ServerExplorer.UI listCmds.Add("SET NOCOUNT ON;"); listCmds.Add(string.Empty); - // Comandos de desactivacion de FKs - foreach (TablaDesc t in db.Tablas) - { - string tableName = string.Format("{0}.{1}", t.Esquema, t.Nombre); - listCmds.Add(string.Format("ALTER TABLE {0} NOCHECK CONSTRAINT all;", tableName)); - } + //// Comandos de desactivacion de FKs + //foreach (TablaDesc t in db.Tablas) + //{ + // string tableName = string.Format("{0}.{1}", t.Esquema, t.Nombre); + // 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); // Prepara informacion a exportar foreach (TablaDesc t in db.Tablas) { string tableName = string.Format("{0}.{1}", t.Esquema, t.Nombre); + listCmds.Add(string.Format("PRINT '*** Importing data of {0}....';", tableName)); List listCmdsTableData = ExportData(tableName); listCmds.AddRange(listCmdsTableData); } - // Comandos de activacion de FKs - foreach (TablaDesc t in db.Tablas) - { - string tableName = string.Format("{0}.{1}", t.Esquema, t.Nombre); - listCmds.Add(string.Format("ALTER TABLE {0} WITH CHECK CHECK CONSTRAINT all;", tableName)); - } + //// Comandos de activacion de FKs + //foreach (TablaDesc t in db.Tablas) + //{ + // 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("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); // Escribir script @@ -341,6 +356,7 @@ namespace ServerExplorer.UI listCmds.Add(string.Format("SET IDENTITY_INSERT {0} ON;", tableName)); listCmds.AddRange(listCmdsInsert); listCmds.Add(string.Format("SET IDENTITY_INSERT {0} OFF;", tableName)); + listCmds.Add("GO"); listCmds.Add(string.Empty); return listCmds;