Delete Rows (Data Management)


Deletes all or the selected subset of rows from the input.

If the input rows are from a feature class or table, all rows will be deleted. If the input rows are from a layer or table view with no selection, all rows will be deleted.



DeleteRows_management (in_rows)
ParameterExplanationData Type

The feature class, layer, table, or table view whose rows will be deleted.

Table View

Code Sample

DeleteRows example 1 (Python window)

The following Python window script demonstrates how to use the DeleteRows function in immediate mode.

import arcpy
from arcpy import env

env.workspace = "C:/data"
arcpy.CopyRows_management("accident.dbf", "C:/output/accident2.dbf")
DeleteRows example 2 (stand-alone script)

The following stand-alone script demonstrates how to use the DeleteRows function to delete rows based on an expression.

# Name:
# Description: Delete rows from a table based on an expression
# Import system modules
import arcpy
from arcpy import env

    # Set environment settings
    env.workspace = "C:/data"

    # Set local variables
    inTable = "accident.dbf"
    outTable = "C:/output/new_accident.dbf"
    tempTableView = "accidentTableView"
    expression = arcpy.AddFieldDelimiters(tempTableView, "Measure") + " = 0"

    # Execute CopyRows to make a new copy of the table
    arcpy.CopyRows_management(inTable, outTable)

    # Execute MakeTableView
    arcpy.MakeTableView_management(outTable, tempTableView)

    # Execute SelectLayerByAttribute to determine which rows to delete
    arcpy.SelectLayerByAttribute_management(tempTableView, "NEW_SELECTION", expression)

    # Execute GetCount and if some features have been selected, then execute
    #  DeleteRows to remove the selected rows.
    if int(arcpy.GetCount_management(tempLayer).getOutput(0)) > 0:

except Exception, e:
    # If an error occurred, print line number and error message
    import traceback, sys
    tb = sys.exc_info()[2]
    print "Line %i" % tb.tb_lineno
    print e.message


Related Topics

Licensing Information

ArcView: Yes
ArcEditor: Yes
ArcInfo: Yes