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})
Parameter | Explanation | Data Type |
in_table | The input table or feature class that contains the field to alter. | Table View; Raster Layer; Raster Catalog 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).
| 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. It is also only applicable if the table is empty. | 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).
| 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.
| Boolean |
Derived Output
Name | Explanation | Data 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