Add Field (Data Management)

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 of the new field.

  • TEXTAny string of characters.
  • FLOAT Fractional numbers between -3.4E38 and 1.2E38.
  • DOUBLE Fractional numbers between -2.2E308 and 1.8E308.
  • SHORT Whole numbers between -32,768 and 32,767.
  • LONG Whole numbers between -2,147,483,648 and 2,147,483,647.
  • DATEDate and/or time.
  • BLOBLong 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.
  • RASTERRaster images. All ArcGIS software-supported raster dataset formats can be stored, but it is highly recommended that only small images be used.
  • GUIDGlobally unique identifier.
String
field_precision
(Optional)

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)

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)

Specifies whether the field can contain null values. Null values 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

ArcView: Yes
ArcEditor: Yes
ArcInfo: Yes

10/27/2014