Table to Table (Conversion)

License Level:BasicStandardAdvanced

Summary

Converts an input table to a dBASE or geodatabase table.

Usage

Syntax

TableToTable_conversion (in_rows, out_path, out_name, {where_clause}, {field_mapping}, {config_keyword})
ParameterExplanationData Type
in_rows

The input table to be converted to a new table.

Table View; Raster Layer
out_path

The destination where the output table will be written.

Workspace
out_name

The name of the output table.

If the Output Location is a folder, convert the Input Rows to a dBASE table by specifying a name with the extension .dbf, or convert the Input Rows to a INFO table by specifying a name with no extension. If the Output Location is a geodatabase, convert the Input Rows to a geodatabase table by specifying a name with no extension.

String
where_clause
(Optional)

An SQL expression used to select a subset of records. The syntax for the expression differs slightly depending on the data source. For example, if you're querying file or ArcSDE geodatabases, shapefiles, coverages, or dBASE or INFO tables, 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
field_mapping
(Optional)

The fields and field contents chosen from the input table. You can add, rename, or delete output fields as well as set properties such as data type and merge rule.

Learn more about choosing and setting the output fields.

Field Mappings
config_keyword
(Optional)

Specifies the default storage parameters (configurations) for geodatabases in a relational database management system (RDBMS). This setting is applicable only when using SDE geodatabase tables.

ArcSDE configuration keywords are set by the database administrator.

String

Code Sample

TableToTable Example (Python Window)

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

import arcpy
from arcpy import env
env.workspace = "C:/data"
arcpy.TableToTable_conversion("vegtable.dbf", "C:/output/output.gdb", "vegtable")
TableToTable Example (stand-alone Python script)

The following stand-alone script demonstrates how to use the TableToTable tool.

# Name: TableToTable_Example2.py
# Description: Use TableToTable with an expression to create a subset
#  of the original table.
 
# Import system modules
import arcpy
from arcpy import env
 
# Set environment settings
env.workspace = "C:/data"
 
# Set local variables
inTable = "vegtable.dbf"
outLocation = "C:/output/output.gdb"
outTable = "estuarine"

# Set the expression, with help from the AddFieldDelimiters function to select the appropriate field delimiters for the data type
expression = arcpy.AddFieldDelimiters(env.workspace, "VEG_TYPE") + " = 'Estuarine'"
 
# Execute TableToTable
arcpy.TableToTable_conversion(inTable, outLocation, outTable, expression)

Environments

Related Topics

Licensing Information

ArcGIS for Desktop Basic: Yes
ArcGIS for Desktop Standard: Yes
ArcGIS for Desktop Advanced: Yes
10/24/2012