Delete Rows (Data Management)

Summary

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

The deletion of all rows or a subset of rows depends on the following:

  • If the input is a feature class or table, all rows will be deleted.
  • If the input is a layer or table view with no selection, all rows will be deleted.
  • If the input is a layer or table view with a selection, only the selected rows will be deleted.

Usage

  • The Input Rows parameter value can be a dBASE table, an enterprise or file geodatabase table or feature class, shapefile, layer, or table view.

  • If this tool is used on feature data, the entire row, including the geometry, will be deleted.

  • Note:

    Deleting all rows from a table with a large number of rows can take time. If the intent is to delete all the rows, consider using the Truncate Table tool instead. See the Truncate Table documentation for important cautionary statements on its use.

Parameters

LabelExplanationData Type
Input Rows

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

Table View

Derived Output

LabelExplanationData Type
Updated Input With Rows Removed

The updated input.

Table View

arcpy.management.DeleteRows(in_rows)
NameExplanationData Type
in_rows

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

Table View

Derived Output

NameExplanationData Type
out_table

The updated input.

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
arcpy.env.workspace = "C:/data"
arcpy.management.CopyRows("accident.dbf", "C:/output/accident2.dbf")
arcpy.management.DeleteRows("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.

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

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

# Set local variables
inTable = "accident.dbf"
outTable = "C:/output/new_accident.dbf"
tempTableView = "accidentTableView"
expression = arcpy.AddFieldDelimiters(tempTableView, "Measure") + " = 0"
 
# Run CopyRows to make a new copy of the table
arcpy.management.CopyRows(inTable, outTable)

# Run MakeTableView
arcpy.management.MakeTableView(outTable, tempTableView)

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

# Run GetCount and if some features have been selected, run
#  DeleteRows to remove the selected rows.
if int(arcpy.management.GetCount(tempTableView)[0]) > 0:
    arcpy.management.DeleteRows(tempTableView)

Environments