Summary
Creates a table view from an input table or feature class. The table view that is created by the tool is temporary and will not persist after the session ends unless the document is saved.
Usage
This tool is commonly used to create a table view with a selected set of attributes or fields.
If an SQL expression is used but returns nothing, the output will be empty.
Field names defined in the Field Info control will be honored in subsequent tools. However, if this tool is the last tool in a model, the field names will be obtained from the source data on disk. To maintain the field names, the new layer has to be written out to a new data using Copy Rows or Copy Features tools.
The field names will be validated by specifying an input workspace. Thus, if the input is a geodatabase feature class, and the output workspace is a folder, the field names may be truncated, since shapefile attributes can only have names of ten characters or less.
A subset of fields can be made unavailable in the new layer by using the Field Info control's visible property. The second column in the control provides a checkbox to specify whether a field will be visible or hidden in the new layer. The default is checked. Uncheck the checkbox to hide that field. You cannot use the hidden fields in a workflow if the newly created layer is input to a subsequent process or tool. If the output is saved to disk, only the fields listed as visible will appear in the new data.
The split policy option on the Field Info control does not apply to this tool.
Syntax
arcpy.management.MakeTableView(in_table, out_view, {where_clause}, {workspace}, {field_info})
Parameter | Explanation | Data Type |
in_table | The input table or feature class. | Table View;Raster Layer |
out_view | The name of the table view to be created. | Table View ;Raster Layer |
where_clause (Optional) | An SQL expression used to select a subset of features. For more information on SQL syntax see the help topic SQL reference for query expressions used in ArcGIS. | SQL Expression |
workspace (Optional) | The input workspace used to validate the field names. If the input is a geodatabase table and the output workspace is a dBASE table, the field names may be truncated, since dBASE fields can only have names of ten characters or less. | Workspace |
field_info (Optional) | Specifies which fields from the input table to make visible in the output table view. | Field Info |
Code sample
The following Python window script demonstrates how to use the MakeTableView function in immediate mode.
import arcpy
arcpy.MakeTableView_management("C:/data/input/crimefrequency.dbf", "crimefreq_tview")
The following stand-alone script demonstrates how to use MakeTableView with a FieldInfo object to filter fields in the output.
# Name: MakeTableView_Example2.py
# Description: Uses a FieldInfo object to select a subset of fields and renaming one field's name.
# Import system modules
import arcpy
# Set data path
intable = "C:/data/tables.gdb/crimefreq"
# Get the fields from the input
fields= arcpy.ListFields(intable)
# Create a fieldinfo object
fieldinfo = arcpy.FieldInfo()
# Iterate through the fields and set them to fieldinfo
for field in fields:
if field.name == "FREQUENCY":
fieldinfo.addField(field.name, "NEWFREQ", "VISIBLE", "")
elif field.name == "CRIME_CAT":
fieldinfo.addField(field.name, field.name, "HIDDEN", "")
elif field.name == "BEAT":
fieldinfo.addField(field.name, field.name, "VISIBLE", "")
# The created crime_view layer will have fields as set in fieldinfo object
arcpy.MakeTableView_management(intable, "crime_view", "", "", fieldinfo)
# To persist the layer on disk make a copy of the view
arcpy.CopyRows_management("crime_view", "C:/temp/newfreq.dbf")
Environments
Licensing information
- Basic: Yes
- Standard: Yes
- Advanced: Yes