Add Field (Data Management)

License Level:BasicStandardAdvanced

Summary

Adds a new field to a table or the table of a feature class, feature layer, raster catalog, and/or rasters with attribute tables.

Usage

Syntax

AddField_management (in_table, field_name, field_type, {field_precision}, {field_scale}, {field_length}, {field_alias}, {field_is_nullable}, {field_is_required}, {field_domain})
ParameterExplanationData Type
in_table

The input table to which the specified field will be added. The field will be added to the existing input table and will not create a new output table.

Fields can be added to feature classes of ArcSDE, file or personal geodatabases, coverages, shapefiles, raster catalogs, stand-alone tables, rasters with attribute tables, and/or layers.

Mosaic Layer; Raster Catalog Layer; Raster Layer; Table View
field_name

The name of the field that will be added to the Input Table.

String
field_type

The field type used in the creation of the new field.

  • TEXTNames or other textual qualities.
  • FLOATNumeric values with fractional values within a specific range.
  • DOUBLENumeric values with fractional values within a specific range.
  • SHORTNumeric values without fractional values within a specific range; coded values.
  • LONGNumeric values without fractional values within a specific range.
  • DATEDate and/or Time.
  • BLOBImages or other multimedia.
  • RASTERRaster images.
  • GUIDGUID values
String
field_precision
(Optional)

Describes the number of digits that can be stored in the field. All digits are counted no matter what side of the decimal they are on.

If the input table is a personal or file geodatabase the field precision value will be ignored.

Long
field_scale
(Optional)

Sets the number of decimal places stored in a field. This parameter is only used in Float and Double data field types.

If the input table is a personal or file geodatabase the field scale value will be ignored.

Long
field_length
(Optional)

The length of the field being added. 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.

Long
field_alias
(Optional)

The alternate name given to the field name. This name is used to give more descriptive names to cryptic field names. The field alias parameter only applies to geodatabases and coverages.

String
field_is_nullable
(Optional)

A geographic feature where there is no associated attribute information. These are different from zero or empty fields and are only supported for fields in a geodatabase.

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

Specifies whether the field being created is a required field for the table; only supported for fields in a geodatabase.

  • NON_REQUIREDThe field is not a required field. This is the default.
  • REQUIREDThe field is a required field. Required fields are permanent and can not be deleted.
Boolean
field_domain
(Optional)

Used to constrain the values allowed in any particular attribute for a table, feature class, or subtype in a geodatabase. You must specify the name of an existing domain for it to be applied to the field.

String

Code Sample

AddField example (Python window)

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

import arcpy
from arcpy import env
env.workspace = "C:/data/airport.gdb"
arcpy.AddField_management("schools", "ref_ID", "LONG", 9, "", "", "refcode", "NULLABLE", "REQUIRED")
AddField example 2 (stand-alone script)

The following stand-alone script demonstrates how to use the AddField tool.

# Name: AddField_Example2.py
# Description: Add a pair of new fields to a table
 
# Import system modules
import arcpy
from arcpy import env
 
# Set environment settings
env.workspace = "C:/data/airport.gdb"
 
# Set local variables
inFeatures = "schools"
fieldName1 = "ref_ID"
fieldPrecision = 9
fieldAlias = "refcode"
fieldName2 = "status"
fieldLength = 10
 
# Execute AddField twice for two new fields
arcpy.AddField_management(inFeatures, fieldName1, "LONG", fieldPrecision, "", "",
                          fieldAlias, "NULLABLE")
arcpy.AddField_management(inFeatures, fieldName2, "TEXT", "", "", fieldLength)

Environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
5/7/2015