Summary
The CreateTable function creates a table or feature class with a defined set of fields in a specified location.
Discussion
This function allows for the definition of fields and can be used to prepare a new feature class or table in combination with the InsertCursor class.
This function is not to be confused with the Create Table tool.
Syntax
CreateTable (path, {fields}, {shape}, configuration)| Parameter | Explanation | Data Type |
path | The path to the new table or feature class. | String |
fields [fields,...] | The fields that will be added to the table or feature class. Fields can be specified using any of the following:
(The default value is None) | Field |
shape | The shape field. If no value is provided, a table will be created. The geometry is defined using a tuple of the geometry type, and, optionally, the spatial reference and whether z- and has m-values will be supported. These values are defined as follows:
The geometry type options are defined as follows:
(The default value is None) | String |
configuration | The configuration keyword applies to enterprise geodatabase data only. It determines the storage parameters of the database table. (The default value is None) | String |
| Data Type | Explanation |
| tuple | A tuple of two values in which the first value is the path to the table or feature class and the second value is a list of the field names. The field names have been validated and may differ from what was specified by the fields parameter. |
Code sample
Create a table using a tuple of field descriptions.
import arcpy
path = r"C:\data\myFGDB.gdb\myTable"
fields = [("street", "Text", "Street Address"),
("city", "Text"),
("state", "Text", "", 2),
("zip", "Long")]
arcpy.da.CreateTable(path, fields)Create a polygon feature class using Field objects from an existing feature class.
import arcpy
tbl = r"C:\data\myFGDB.gdb\myTable"
path = r"C:\data\myFGDB.gdb\polyFC"
fields = [i for i in arcpy.ListFields(tbl) if (i.type != "OID")]
table_path, field_names = arcpy.da.CreateTable(path, fields, ("POLYGON", 4326))