Alter Field (Data Management)
Summary
Rename fields and field aliases.
Usage
-
This tool provides the ability to rename fields or rename 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 in found in network analysis layers can result in corrupted data or unexpected behavior.
Syntax
AlterField_management (in_table, field, {new_field_name}, {new_field_alias})
Parameter | Explanation | Data Type |
in_table |
Input table or feature class that contains the field to alter. | Table View |
field |
The name of the field to alter. | Field |
new_field_name (Optional) |
The new name for the field. | String |
new_field_alias (Optional) |
The new field alias for the field. | String |
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, 'ELEVATION', 'Elevation in Metres')
Environments
Related Topics
Licensing Information
ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
5/7/2015