Monday, December 3, 2012

Truncate Table, A New Way To Erase Rows

Truncate table is the 10.1 way to erase ALL the rows in a table or feature class.  It will ignore any sql query, so use this tool carefully.

Some Notes:

  • Supported data types are simple, meaning no terrains, topologies, etc..
  • Data must be unversioned to execute
  • After rows are removed, the data is unrecoverable, so make sure you know what you are doing before you go and use this.

This is a good tool for workflows where you need to clear out rows on some regular basis.

Usage Example:
import arcpy
from arcpy import env
wrksp = r"c:\temp\data.gdb"
env.workspace = wrksp
fcs = arcpy.ListFeatureClasses()
for fc in fcs:
   arcpy.TruncateTable_management(fc)
del fcs


Enjoy