Create Database View (Data Management)

Summary

Creates a view in a database based on an SQL expression.

Usage

  • The SQL expression used to define the view is validated by the database upon execution of the tool. Valid syntax for the view definition is determined by the underlying database. If the syntax is incorrect, an error message is returned.

  • This tool is supported for databases, enterprise geodatabases, mobile geodatabases, and file geodatabases.

  • Views created in a geodatabase using this tool are not registered with the geodatabase.

  • If a spatial column is included in the view, the geometry storage type of the column must be an SQL data type (such as ST_Geometry or Geometry), not a binary geometry storage type.

  • Learn more about constructing a query and see examples of SQL expressions.

Syntax

arcpy.management.CreateDatabaseView(input_database, view_name, view_definition)
ParameterExplanationData Type
input_database

The database that contains the tables or feature classes used to construct the view. This database is also where the view will be created.

Workspace
view_name

The name of the view that will be created in the database.

String
view_definition

An SQL statement used to construct the view.

String

Derived Output

NameExplanationData Type
out_layer

The output database view.

Table

Code sample

CreateDatabaseView example 1 (Python window)

Create a database view in an enterprise geodatabase.

import arcpy
arcpy.CreateDatabaseView_management("c:/Connections/city_data.sde","trees","select objectid, owner, parcel from inventory where type = trees")
CreateDatabaseView example 2 (Python window)

Create a database view in a file geodatabase.

import arcpy 
arcpy.CreateDatabaseView_management("C:\\Connections\\city_data.gdb",
                                    "trees",
                                    "select objectid, owner, parcel from inventory where type = trees")
CreateDatabaseView example 3 (Python window)

Create a database view in a mobile geodatabase.

import arcpy
arcpy.CreateDatabaseView_management("C:\\mymgdbs\\facilities.geodatabase",
                                    "dog_parks",
                                    "select objectid, park_name, park_address, park_hours from parks where park_type = dog")

Environments

Licensing information

  • Basic: No
  • Standard: Yes
  • Advanced: Yes

Related topics