Alter Field (Data Management)

Summary

Renames fields and field aliases, or alters field properties.

Usage

  • This tool provides the ability to rename fields or field aliases for any geodatabase table or feature class.

  • When using in memory feature classes or tables, renaming the ObjectID, Shape, or other required fields such as those found in network analysis layers can result in corrupted data or unexpected behavior.

Syntax

AlterField(in_table, field, {new_field_name}, {new_field_alias}, {field_type}, {field_length}, {field_is_nullable}, {clear_field_alias})
ParameterExplanationData Type
in_table

The input table or feature class that contains the field to alter.

Table View; Raster Layer; Mosaic Layer
field

The name of the field to alter. If the field is a required field (isRequired=true), only the field alias can be altered.

Field
new_field_name
(Optional)

The new name for the field.

String
new_field_alias
(Optional)

The new field alias for the field.

String
field_type
(Optional)

Specifies the new field type for the field. This property is only applicable if the input table is empty (does not contain records).

  • TEXTAny string of characters.
  • FLOAT Fractional numbers between -3.4E38 and 1.2E38.
  • DOUBLE Fractional numbers between -2.2E308 and 1.8E308.
  • SHORT Whole numbers between -32,768 and 32,767.
  • LONG Whole numbers between -2,147,483,648 and 2,147,483,647.
  • DATEDate and/or time.
  • BLOBLong sequence of binary numbers. You need a custom loader or viewer or a third-party application to load items into a BLOB field or view the contents of a BLOB field.
  • RASTERRaster images. All ArcGIS software-supported raster dataset formats can be stored, but it is highly recommended that only small images be used.
  • GUIDGlobally unique identifier.
String
field_length
(Optional)

The new length of the field. This sets the maximum number of allowable characters for each record of the field. This option is only applicable to fields of type TEXT or BLOB. If the table is empty, the field length can be either increased or decreased. If the table is not empty, the length can only be increased from the current value.

Long
field_is_nullable
(Optional)

Specifies whether the field can contain null values. Null values are only supported for fields in a geodatabase. This option is only applicable if the input table is empty (does not contain records).

  • NON_NULLABLEThe field will not allow null values.
  • NULLABLEThe field will allow null values. This is the default.
Boolean
clear_field_alias
(Optional)

Specifies whether the alias for the input field will be cleared. The field alias parameter must be empty to clear the alias of the field.

  • CLEAR_ALIASThe field alias will be cleared (set to null).
  • DO_NOT_CLEARThe field alias will not be cleared. This is the default.
Boolean

Derived Output

NameExplanationData Type
out_table

The updated input table.

Table View; Raster Layer; Mosaic Layer

Code sample

AlterField example 1 (Python window)

The following Python window script demonstrates how to use the AlterField tool in immediate mode.

arcpy.AlterField_management(r'C:\Data\Garbo.gdb\Khyber', 'Elev', 'ELEVATION', 'Elevation in Metres')
AlterField example 2 (stand-alone script)

The following Python window script demonstrates how to use the AlterField tool in a stand-alone script.

#Import geoprocessing
import arcpy

#Set workspace
arcpy.env.workspace = r'C:\Data\Garbo.gdb'

#Loop through feature classes looking for a field named 'elev'
fcList = arcpy.ListFeatureClasses() #get a list of feature classes
for fc in fcList:  #loop through feature classes
    fieldList = arcpy.ListFields(fc)  #get a list of fields for each feature class
    for field in fieldList: #loop through each field
        if field.name.lower() == 'elev':  #look for the name elev
            arcpy.AlterField_management(fc, field.name, 'ELEVATION', 'Elevation in Metres')
AlterField example 3 (stand-alone script)

The following Python window script demonstrates how to use the AlterField tool on an empty feature class in a stand-alone script.

#Import geoprocessing
import arcpy

#Set local variables
fc = "C:/Data/Garbo.gdb/trails" #Note:empty feature class
field = "condition_rating" #short int, non nullable field
new_name = "notes"
new_alias = "Comments on Trail Condition"
new_type = "TEXT"
new_length = "60"
new_is_nullable = "NULLABLE"
clear_alias = "FALSE"

#Alter the properties of a non nullable, short data type field to become a text field
arcpy.AlterField_management(fc, field, new_name, new_alias, new_type, new_length, new_is_nullable, clear_alias)

Environments

Licensing information

  • Basic: Yes
  • Standard: Yes
  • Advanced: Yes

Related topics