WEB LISTING A: Snippet of the VB COM Object's Drop_Save_Table_Indexes Method 'This custom COM component is installed on every server. 'Create and connect to the local SQL Server. Set oServer = New SQLDMO.SQLServer oServer.LoginTimeout = 30 oServer.Connect , "account", "password" 'Find the subscription database. Set oDB = oServer.Databases(sDestination_db) 'Find the named table. Set oTable = oDB.Tables(sTable, sOwner) '1. Drop all foreign key constraints referencing the specified table. Set FK_QueryResults = oTable.EnumReferencingKeys For i = 1 To FK_QueryResults.Rows Set oFK = _ oDB.Tables(FK_QueryResults.GetColumnString(i,1)). Keys(FK_QueryResults.GetColumnString(i, 2)) sFK = sFK + vbCrLf _ + Replace(oFK.Script, "REFERENCES ", "REFERENCES [" + sOwner + "].") oFK.Remove Next '2.1 Drop all nonclustered primary and unique key constraints. For i = oTable.Keys.Count To 1 Step -1 If oTable.Keys(i).Type = SQLDMOKey_Primary Or _ oTable.Keys(i).Type = SQLDMOKey_Unique Then 'Save the clustered key for dropping last. If oTable.Keys(i).Clustered Then Set oClustered_key = oTable.Keys(i) Else 'Save script and remove nonclustered key. sNon_Clustered_Key = sNon_Clustered_Key + vbCrLf + vbCrLf + oTable.Keys(i).Script oTable.Keys(i).Remove End If End If Next '2.2 Drop all nonclustered, non-key, and nonstatistical (non-Hypothetical) indexes. For i = oTable.Indexes.Count To 1 Step -1 If (oTable.Indexes(i).Type And SQLDMOIndex_Clustered) <> SQLDMOIndex_Clustered And _ (oTable.Indexes(i).Type And SQLDMOIndex_DRIPrimaryKey) <> SQLDMOIndex_DRIPrimaryKey And _ (oTable.Indexes(i).Type And SQLDMOIndex_DRIUniqueKey) <> SQLDMOIndex_DRIUniqueKey And _ (oTable.Indexes(i).Type And SQLDMOIndex_Hypothetical) <> SQLDMOIndex_Hypothetical Then sNon_Clustered_Index = sNon_Clustered_Index + vbCrLf + vbCrLf + _ "EXECUTE('" + LTrim(Left(oTable.Indexes(i).Script, _ InStrRev(oTable.Indexes(i).Script, vbCrLf + "GO") - 1)) + "')" oTable.Indexes(i).Remove End If Next '3. Drop clustered index or clustered key. If oTable.HasClusteredIndex Then 'Clustered index exists. If oClustered_key Is Nothing Then 'No clustered key found above (in step 2.1). sClustered = "EXECUTE('" + _ LTrim(Left(oTable.ClusteredIndex.Script, _ InStrRev(oTable.ClusteredIndex.Script, vbCrLf + "GO") - 1)) + "')" oTable.ClusteredIndex.Remove Else 'Clustered key (primary or unique) exists (found in step 2.1). sClustered = oClustered_key.Script oClustered_key.Remove End If End If 'Combine all index and key creation scripts in the following order: '1. Clustered index or clustered key, 2.1 nonclustered primary and unique keys, '2.2 nonclustered indexes, 3. foreign keys sIndex_Script = sClustered + vbCrLf + sNon_Clustered_Key + vbCrLf +_ sNon_Clustered_Index + vbCrLf + sFK 'To create the recreation stored procedure with an empty body for the first time, 'do the following: Set oSP = New SQLDMO.StoredProcedure oSP.Name = "hub_create_" + sPublication + "_indexes" oSP.Text = "Create Procedure " + oSP.Name + " As" oDB.StoredProcedures.Add oSP 'To update the stored procedure with the recreation scripts given the stored procedure object, 'do the following: sIndex_Script = "Alter Procedure " + "hub_create_" + sPublication + "_indexes As" + sIndex_Script oSP.Alter sIndex_Script 2