Assign Default To Field (Data Management)

Summary

This tool will create a default value for a specified field. Whenever a new row is added to the table or feature class, the specified field will be set to this default value.

Usage

Syntax

AssignDefaultToField_management (in_table, field_name, default_value, {subtype_code})
ParameterExplanationData Type
in_table

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

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

Field that will have the default value added to it each time a new row is added to the table or feature class.

Field
default_value

The string for the default value to be added to each new table or feature class. The field type controls what kind of string can be added.

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

The subtypes that can participate in the default value. You specify the subtypes to be used.

String

Code Sample

AssignDefaultToField example (Python window)

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

import arcpy
from arcpy import env
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 tool.

# Name: AssignDefaultToField_Example2.py
# Description: Assign a new default to a field along with subtypes
# Author: ESRI
 
# Import system modules
import arcpy
from arcpy import env
 
# Set environment settings
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

Related Topics

Licensing Information

ArcView: Yes
ArcEditor: Yes
ArcInfo: Yes

10/27/2014