Make Table View (Data Management)

Summary

Creates a table view from an input table or feature class. The table view that is created 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 based on an SQL expression with a selected set of attribute fields.

  • If an SQL expression is used but returns nothing, the output will be empty.

Parameters

LabelExplanationData Type
Input Table

The input table or feature class.

Table View; Raster Layer
Table Name

The name of the table view to be created.

Table View; Raster Layer
Expression
(Optional)

An SQL expression used to select a subset of records.

SQL Expression
Output Workspace
(Optional)

This parameter is not used.

In ArcGIS Desktop, output field names are validated based on this workspace. In ArcGIS Pro, this tool does not support changing the field names because table views do not support field names that differ from the underlying data source.

Workspace
Field Info
(Optional)

The fields from the input table that will be included in the output layer. You can remove input fields by setting them to not visible. Renaming fields and the use of split policies are not supported.

Field Info

arcpy.management.MakeTableView(in_table, out_view, {where_clause}, {workspace}, {field_info})
NameExplanationData 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)

This parameter is not used.

In ArcGIS Desktop, output field names are validated based on this workspace. In ArcGIS Pro, this tool does not support changing the field names because table views do not support field names that differ from the underlying data source.

Workspace
field_info
(Optional)

The fields from the input table that will be included in the output layer. You can remove input fields by setting them to not visible. Renaming fields and the use of split policies are not supported.

Field Info

Code sample

MakeTableView example 1 (Python window)

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

import arcpy

arcpy.management.MakeTableView("C:/data/input/crimefrequency.dbf", "crimefreq_tview")
MakeTableView example 2 (stand-alone script)

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 use with MakeTableView

# 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 input fields and add them to fieldinfo
for field in fields:
    if field.name == "CRIME_ADDRESS":
        # Make the CRIME_ADDRESS field hidden
        fieldinfo.addField(field.name, field.name, "HIDDEN", "")
    else:
        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)

# Persist the view to a table
arcpy.CopyRows_management("crime_view", "C:/data/tables.gdb/crime_copy")

Environments

Related topics