Alter Fields (multiple) (Data Management)

Summary

Alters the field properties of multiple fields in a feature class or table.

Usage

    Caution:

    This tool modifies the input data. See Tools that modify or update the input data for more information and strategies to avoid undesired data changes.

  • This tool allows you to rename fields or field aliases for a geodatabase table or feature class.

  • You can use this tool to modify the field alias of a field in a table or view that is registered with the geodatabase.

  • If an input field is a required field, only the field alias can be modified.

Parameters

LabelExplanationData Type
Input Table

The input geodatabase table or feature class that contains the field that will be altered.

Table View; Raster Layer; Mosaic Layer
Field Properties
(Optional)

The input table fields and their properties that will be altered.

  • Field Name—The name of the field that will be altered. If the field is a required field, only the field alias will be altered.
  • New Field Name (optional)—The new name for the field.
  • New Field Alias (optional)—The new field alias for the field.
  • New Field Type (optional)—Specifies the new field type for the field. This column is only applicable if the input table is empty (does not contain records).
  • New Field Length (optional)—The new length of the field (Long type). 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 (binary data). If the table is empty, the field length can be increased or decreased. If the table is not empty, the length can only be increased from the current value.
  • New Field IsNullable (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 table is empty (does not contain records). If checked, the field can contain null values. This is the default. If unchecked, the field cannot contain null values.
  • Clear Alias (optional)—Specifies whether the alias for the input field will be cleared. The New Field Alias value must be empty to clear the alias of the field. If checked, the field alias will be cleared (set to null). If unchecked, the field alias will not be cleared. This is the default.

Available field types are as follows:

  • Short (16-bit integer)—The field type will be short. Short fields support whole numbers between -32,768 and 32,767.
  • Long (32-bit integer)—The field type will be long. Long fields support whole numbers between -2,147,483,648 and 2,147,483,647.
  • Big integer (64-bit integer)—The field type will be big integer. Big integer fields support whole numbers between -(253) and 253.
  • Float (32-bit floating point)—The field type will be float. Float fields support fractional numbers between -3.4E38 and 1.2E38.
  • Double (64-bit floating point)—The field type will be double. Double fields support fractional numbers between -2.2E308 and 1.8E308.
  • Text—The field type will be text. Text fields support a string of characters.
  • Date—The field type will be date. Date fields support date and time values.
  • Date (high precision)—The field type will be high precision date. High precision date fields support date and time values with millisecond time.
  • Date only—The field type will be date only. Date only fields support date values with no time values.
  • Time only—The field type will be time only. Time only fields support time values with no date values.
  • Timestamp offset—The field type will be timestamp offset. Timestamp offset fields support a date, time, and offset from a UTC value.
  • Blob (binary data)—The field type will be BLOB. BLOB fields support data stored as a long 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.
  • GUID (globally unique identifier)—The field type will be GUID. GUID fields store registry-style strings consisting of 36 characters enclosed in curly brackets.
  • Raster imagery—The field type will be raster. Raster fields can store raster data in or alongside the geodatabase. All ArcGIS software-supported raster dataset formats can be stored, but it is recommended that only small images be used.
Value Table

Derived Output

LabelExplanationData Type
Updated Input Table

The updated input table.

Table View; Raster Layer; Mosaic Layer

arcpy.management.AlterFields(in_table, {field_description})
NameExplanationData Type
in_table

The input geodatabase table or feature class that contains the field that will be altered.

Table View; Raster Layer; Mosaic Layer
field_description
[[Field Name, {New Field Name}, {New Field Alias}, {New Field Type}, {New Field Length}, {New Field IsNullable}, {Clear Alias}],...]
(Optional)

The input table fields and their properties that will be altered.

  • Field Name—The name of the field that will be altered. If the field is a required field, only the field alias will be altered.
  • New Field Name (optional)—The new name for the field.
  • New Field Alias (optional)—The new field alias for the field.
  • New Field Type (optional)—Specifies the new field type for the field. This option is only applicable if the input table is empty (does not contain records).
  • New 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 increased or decreased. If the table is not empty, the length can only be increased from the current value.
  • New Field IsNullable (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 table is empty (does not contain records). If set to True, the field can contain null values. This is the default. If set to False, the field cannot contain null values.
  • Clear Alias (optional)—Specifies whether the alias for the input field will be cleared. The New Field Alias value must be empty to clear the alias of the field. If set to True, the field alias will be cleared (set to null). If set to False, the field alias will not be cleared. This is the default.

Available field types are as follows:

  • SHORT—The field type will be short. Short fields support whole numbers between -32,768 and 32,767.
  • LONG—The field type will be long. Long fields support whole numbers between -2,147,483,648 and 2,147,483,647.
  • BIGINTEGER—The field type will be big integer. Big integer fields support whole numbers between -(253) and 253.
  • FLOAT—The field type will be float. Float fields support fractional numbers between -3.4E38 and 1.2E38.
  • DOUBLE—The field type will be double. Double fields support fractional numbers between -2.2E308 and 1.8E308.
  • TEXT—The field type will be text. Text fields support a string of characters.
  • DATE—The field type will be date. Date fields support date and time values.
  • DATEHIGHPRECISION—The field type will be high precision date. High precision date fields support date and time values with millisecond time.
  • DATEONLY—The field type will be date only. Date only fields support date values with no time values.
  • TIMEONLY—The field type will be time only. Time only fields support time values with no date values.
  • TIMESTAMPOFFSET—The field type will be timestamp offset. Timestamp offset fields support a date, time, and offset from a UTC value.
  • BLOB—The field type will be BLOB. BLOB fields support data stored as a long 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.
  • GUID—The field type will be GUID. GUID fields store registry-style strings consisting of 36 characters enclosed in curly brackets.
  • RASTER—The field type will be raster. Raster fields can store raster data in or alongside the geodatabase. All ArcGIS software-supported raster dataset formats can be stored, but it is recommended that only small images be used.

Value Table

Derived Output

NameExplanationData Type
out_table

The updated input table.

Table View; Raster Layer; Mosaic Layer

Code sample

AlterFields example 1 (stand-alone script)

The following stand-alone script demonstrates how to use the AlterFields function to alter the field aliases of fields in a feature class.

import arcpy

test_class = arcpy.management.CreateFeatureclass(out_gdb, "new_fc", geometry_type='POLYGON')
field_description = [
    ['SHORT_FIELD', 'SHORT', 'SHORT_FIELD_Alias', '#', '#', '#'],
    ['LONG_FIELD', 'LONG', 'LONG_FIELD_Alias', '#', '#', '#'],
    ['BIGINTEGER_FIELD', 'BIGINTEGER', 'BIGINTEGER_FIELD_Alias', '#', '#', '#'], 
    ['FLOAT_FIELD', 'FLOAT', 'FLOAT_FIELD_Alias', '#', '#', '#'],
    ['DOUBLE_FIELD', 'DOUBLE', 'DOUBLE_FIELD_Alias', '#', '#', '#'],
    ['TEXT_FIELD', 'TEXT', 'TEXT_FIELD_Alias', '#', '#', '#'],
    ['DATE_FIELD', 'DATE', 'DATE_FIELD_Alias', '#', '#', '#'],
    ['DATEONLY_FIELD', 'DATEONLY', 'DATEONLY_FIELD_Alias', '#', '#', '#'],
    ['TIMEONLY_FIELD', 'TIMEONLY', 'TIMEONLY_FIELD_Alias', '#', '#', '#'],
    ['TIMESTAMPOFFSET_FIELD', 'TIMESTAMPOFFSET', 'TIMESTAMPOFFSET_FIELD_Alias', '#', '#', '#']
]
arcpy.management.AddFields(test_class, field_description, None)

alter_field_description = [
    ['SHORT_FIELD', 'SHORT_FIELD_altered', '#', '#', '#', '#'],
    ['LONG_FIELD', 'LONG_FIELD_altered', '#', '#', '#', '#'],
    ['BIGINTEGER_FIELD', 'BIGINTEGER_FIELD_altered', '#', '#', '#', '#'],
    ['FLOAT_FIELD', 'FLOAT_FIELD_altered', '#', '#', '#', '#'],
    ['DOUBLE_FIELD', 'DOUBLE_FIELD_altered', '#', '#', '#', '#'],
    ['TEXT_FIELD', 'TEXT_FIELD_altered', '#', '#', '#', '#'],
    ['DATE_FIELD', 'DATE_FIELD_altered', '#', '#', '#', '#'],
    ['DATEONLY_FIELD', 'DATEONLY_FIELD_altered', '#', '#', '#', '#'],
    ['TIMEONLY_FIELD', 'TIMEONLY_FIELD_altered', '#', '#', '#', '#'],
    ['TIMESTAMPOFFSET_FIELD', 'TIMESTAMPOFFSET_FIELD_altered', '#', '#', '#', '#']
]
arcpy.management.AlterFields(in_table=test_class, field_description=alter_field_description)
AlterFields example 2 (stand-alone script)

The following stand-alone script demonstrates how to use the AlterFields function to alter the is nullable field property of fields in an empty table.

import arcpy

test_class = arcpy.management.CreateTable(out_gdb, "new_table")
field_description = [
    ['SHORT_FIELD', 'SHORT', 'SHORT_FIELD_Alias', '#', '#', '#'],
    ['LONG_FIELD', 'LONG', 'LONG_FIELD_Alias', '#', '#', '#'],
    ['BIGINTEGER_FIELD', 'BIGINTEGER', 'BIGINTEGER_FIELD_Alias', '#', '#', '#'],
    ['FLOAT_FIELD', 'FLOAT', 'FLOAT_FIELD_Alias', '#', '#', '#'],
    ['DOUBLE_FIELD', 'DOUBLE', 'DOUBLE_FIELD_Alias', '#', '#', '#'],
    ['TEXT_FIELD', 'TEXT', 'TEXT_FIELD_Alias', '#', '#', '#'],
    ['DATE_FIELD', 'DATE', 'DATE_FIELD_Alias', '#', '#', '#'],
    ['DATEONLY_FIELD', 'DATEONLY', 'DATEONLY_FIELD_Alias', '#', '#', '#'],
    ['TIMEONLY_FIELD', 'TIMEONLY', 'TIMEONLY_FIELD_Alias', '#', '#', '#'],
    ['TIMESTAMPOFFSET_FIELD', 'TIMESTAMPOFFSET', 'TIMESTAMPOFFSET_FIELD_Alias', '#', '#', '#']
]

arcpy.management.AddFields(test_class, field_description, None)

# Change the nullable property to true
alter_field_description = [
    ['SHORT_FIELD', '#', '#', '#','#', 'true', '#'],
    ['LONG_FIELD', '#', '#', '#','#', 'true', '#'],
    ['BIGINTEGER_FIELD', '#', '#', '#','#', 'true', '#'],
    ['FLOAT_FIELD', '#', '#', '#','#', 'true', '#'],
    ['DOUBLE_FIELD', '#', '#', '#','#', 'true', '#'],
    ['TEXT_FIELD', '#', '#', '#','#', 'true', '#'],
    ['DATE_FIELD', '#', '#', '#','#', 'true', '#'],
    ['DATEONLY_FIELD', '#', '#', '#','#', 'true', '#'],
    ['TIMEONLY_FIELD', '#', '#', '#','#', 'true', '#'],
    ['TIMESTAMPOFFSET_FIELD', '#', '#', '#','#', 'true', '#']
]

arcpy.management.AlterFields(in_table=test_class, field_description=alter_field_description)

Environments

Licensing information

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

Related topics