Make Table View (Data Management)

License Level:BasicStandardAdvanced

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

Syntax

MakeTableView_management (in_table, out_view, {where_clause}, {workspace}, {field_info})
ParameterExplanationData 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. The syntax for the expression differs slightly depending on the data source. For example, if you're querying file or ArcSDE geodatabases, shapefiles, or coverages, enclose field names in double quotes:

"MY_FIELD"

If you're querying personal geodatabases, enclose fields in square brackets:

[MY_FIELD]

In Python, strings are enclosed in matching single or double quotes. To create a string that contains quotes (as is common with a WHERE clause in SQL expressions), you can escape the quotes (using a backslash) or triple quote the string. For example, if the intended WHERE clause is

"CITY_NAME" = 'Chicago'

you could enclose the entire string in double quotes, then escape the interior double quotes like this:

" \"CITY_NAME\" = 'Chicago' "

Or you could enclose the entire string in single quotes, then escape the interior single quotes like this:

' "CITY_NAME" = \'Chicago\' '

Or you could enclose the entire string in triple quotes without escaping:

""" "CITY_NAME" = 'Chicago' """

For more information on SQL syntax and how it differs between data sources, 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. The new names may be reviewed and altered using the field information control.

Workspace
field_info
(Optional)

Specifies which fields from the input table to rename and make visible in the output table view.

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.MakeTableView_management("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 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

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
11/18/2013