Is it possible to distinguish (with ArcPy) a featureclass in an RDBMS (SQL Server, in this case) that is a table vs a registered spatial view that was created with the command line tools?

Spatial view is stored in an ArcSDE 10.0 geodatabase, and arcpy version <= 10.3.1.

  • 1
    Shouldn't use sdetable to create views (except for SDEBINARY geometry, which shouldn't be used, either). Please specify ArcGIS version.
    – Vince
    Dec 28, 2016 at 21:46
  • 1
    ArcPy doesn't distinguish between feature classes based on tables and those based on views, and ArcObjects doesn't seem to, either. So then it becomes an exercise in using an arcpy.ArcSDESQLExecute cursor for an RDBMS-specific view test. 10.0 geodatabases are not supported by 10.4.x or 10.5, so leaving the database back at 10.0 is likely to cause issues soon.
    – Vince
    Dec 28, 2016 at 23:03

1 Answer 1


@Vince pointed out the arcpy.ArcSDESQLExecute command.

Here is a function I put together to return True/False for finding a Spatial View, based on the code sample from http://pro.arcgis.com/en/pro-app/arcpy/classes/arcsdesqlexecute.htm

def isSpatialView(egdb, fc):
    desc = arcpy.Describe(fc)
    fcName = desc.name
    db, schema, tableName = fcName.split(".")

    #Connect to the GDB
    egdb_conn = arcpy.ArcSDESQLExecute(egdb)

    #Execute SQL against the table
    sql = r"IF EXISTS(select * FROM sys.views where name = '{0}') SELECT 1 ELSE SELECT 0".format(tableName)

    egdb_return = egdb_conn.execute(sql)
    if egdb_return == 1:
        return True
        return False

#Connect to your DB
egdb = r'Database Connections\Connection to [your_database].sde'

#Set the ArcGIS workspace
arcpy.env.workspace = egdb 

#Get all feature classes in the workspace
fcList = arcpy.ListFeatureClasses()

#report if featureclass is a Spatial View
for fc in fcList:
    arcpy.AddMessage( isSpatialView(egdb, fc) )

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.