Assign Default To Field (Data Management)

Summary

Creates a default value for a specified field. When a new row is added to the table or feature class, the specified field will be set to this default value.

Usage

  • The default value is dependent on the field type chosen in the Field Name parameter. If you choose a field that is type LONG (long integer), the default value must be type LONG.

  • Adding subtypes to the default value is optional. If you add a subtype, there must be a subtype field in the feature class or table. You can set the subtype field using the Set Subtype Field tool.

  • You can also view and manage subtypes in Subtypes view which can be opened by clicking the Subtypes button found in the Design section of the Data ribbon, or by clicking the Subtypes button on the Fields view ribbon.

  • This tool can also be used to clear the default value of a field or subtype.

Syntax

arcpy.management.AssignDefaultToField(in_table, field_name, {default_value}, {subtype_code}, {clear_value})
ParameterExplanationData Type
in_table

The input table or feature class that will have a default value added to one of its fields.

Mosaic Layer; Raster Layer; Table View
field_name

The field to which the default value will be added each time a new row is added to the table or feature class.

Field
default_value
(Optional)

The default value to be added to each new table or feature class. The value entered must match the data type of the field.

String
subtype_code
[subtype_code,...]
(Optional)

The subtypes that can participate in the default value.

String
clear_value
(Optional)

Specifies whether the default value for either the field or the subtype will be cleared. To clear the default value, the default_value parameter must be passed in as an empty string. To clear the default value for the subtype, you must also specify the subtype to be cleared.

  • CLEAR_VALUEThe default value will be cleared (set to null).
  • DO_NOT_CLEARThe default value will not be cleared. This is the default.
Boolean

Derived Output

NameExplanationData Type
out_table

The updated input table.

Table View; Raster Layer; Mosaic Layer

Code sample

AssignDefaultToField example (Python window)

The following Python window script demonstrates how to use the AssignDefaultToField function in immediate mode.

import arcpy
arcpy.env.workspace = "C:/data/Montgomery.gdb/Landbase"
arcpy.CopyFeatures_management("blocks", "C:/output/output.gdb/blocks")
arcpy.AssignDefaultToField_management("C:/output/output.gdb/blocks", "Res", 1,
                                      ["0: Non-Residental", "1: Residental"])
AssignDefaultToField example 2 (stand-alone script)

The following stand-alone script demonstrates how to use the AssignDefaultToField function.

# Name: AssignDefaultToField_Example2.py
# Description: Assign a new default to a field along with subtypes
 
# Import system modules
import arcpy
 
# Set environment settings
arcpy.env.workspace = "c:/data/Montgomery.gdb/Landbase"
 
# Set local variables
inFeatures = "blocks"
outFeatureClass = "c:/output/output.gdb/blocks"
fieldName = "Res"
defaultValue = 1
subTypes = ["0: Non-Residental", "1: Residental"]
 
# Execute CopyFeatures to make new copy of the input
arcpy.CopyFeatures_management(inFeatures, outFeatureClass)
 
# Execute AssignDefaultToField
arcpy.AssignDefaultToField_management(outFeatureClass, fieldName, 
                                      defaultValue, subTypes)

Environments

Licensing information

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

Related topics