Summary
Rename fields and field aliases, or alter field properties.
Usage
This tool provides the ability to rename fields or rename field aliases for any geodatabase table or feature class.
For empty geodatabase tables or feature classes, you can change field properties such as the field type, length, or nullability.
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}, {field_type}, {field_length}, {field_is_nullable}, {clear_field_alias})
Parameter | Explanation | Data Type |
in_table | 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 may 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) | The new field type for the field. 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 on fields of type TEXT or BLOB. Only applicable if table is empty. | Long |
field_is_nullable (Optional) | Determines if the field can contain null values. Null values are only supported for fields in a geodatabase. Only applicable if the input table is empty (does not contain records).
| Boolean |
clear_field_alias (Optional) | Specify whether to clear the alias for the input field. The field alias parameter must be empty to clear the alias of the field.
| Boolean |
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
- ArcGIS Desktop Basic: Yes
- ArcGIS Desktop Standard: Yes
- ArcGIS Desktop Advanced: Yes