KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Sample Code: How to drop or disable all indexes
PRODUCT: 4D | VERSION: 12.5 | PLATFORM: Mac & Win
Published On: August 27, 2013

Here is a snippet of code that can be used for dropping all indexes in a structure:

ARRAY LONGINT(indexedCols;0)
ARRAY LONGINT(indexedTabs;0)
C_LONGINT($a)
Begin SQL
   SELECT COLUMN_ID, TABLE_ID
   FROM _USER_IND_COLUMNS
   INTO :indexedCols, :indexedTabs;

End SQL
For ($a;1;Size of array(indexedCols))
   DELETE INDEX(Field(indexedTabs{$a};indexedCols{$a}))
End for


It is not always necessary to drop all indexes; sometimes disabling them temporarily is sufficient. To disable indexes you can use code like this:

Begin SQL
   ALTER DATABASE DISABLE INDEXES;
   ALTER DATABASE DISABLE CONSTRAINTS;

End SQL

   // do stuff while indexes are disabled...

Begin SQL
   ALTER DATABASE ENABLE INDEXES;
   ALTER DATABASE ENABLE CONSTRAINTS;

End SQL


For more information on disabling indexes please see the ALTER DATABASE command reference.