Get List of all tables?

2356
3
Jump to solution
06-28-2013 09:22 AM
AdrianaCalleja
New Contributor
Hi!

I'd like to know, how could I get a list of all my layers contents in SDE?


Regards,

Thanks in advance.

aecalleja
0 Kudos
1 Solution

Accepted Solutions
WilliamCraft
MVP Regular Contributor
From the RDBMS directly, you can use the following queries:

To get a list of all tables registered with the geodatabase, use:

select table_name from sde.TABLE_REGISTRY;


To get a list of all layers (i.e., all GDB-registered tables which have a spatial column) within SDE, use:

select table_name from sde.LAYERS;


If you are wanting to know more spatial-specific information, the following Python script has worked for me (substitute your own info):

import os, subprocess, arcgisscripting, string, sys, os

gp = arcgisscripting.create(9.3)
gp.workspace = r"C:\Users\User1\AppData\Roaming\ESRI\ArcCatalog\test.sde"    

server = 'server'

def describeFeatures(sdeWorkspace,logWorkspace, logName,instance,user, psswd):
   
    logfile = open(os.path.join(logWorkspace, logName), 'w')

    datasets = gp.listdatasets("","")

    for dataset in datasets:

        gp.workspace = sdeWorkspace + os.sep + dataset

        for fc in gp.ListFeatureClasses():
               
                args = ['sdelayer', '-o', 'describe_long', '-l', str(fc) + ',SHAPE','-i', instance, \
                       '-u', user, '-p', psswd, '-s', server]

                p = subprocess.Popen(args, stdout=subprocess.PIPE)
                output = p.stdout.read()
               
                logfile.write(fc)
                logfile.write(output)
                logfile.write("\n")
               
                print fc, output
    logfile.close()

if __name__== "__main__":
   
    #connection to database

    sdeWorkspace = gp.workspace
    logName = "FeatureInfo.txt"
    logWorkspace = r"C:\Users\user1\Documents\python\DescribeFeatureClasses"
    instance = 'esri_metrorep'
    user = 'sde'
    psswd = 'sde'
    describeFeatures(sdeWorkspace,logWorkspace, logName,instance,user,psswd)

View solution in original post

0 Kudos
3 Replies
VinceAngelo
Esri Esteemed Contributor
This question is quite confusing.

Do you want a list of tables or a list of layers?  Or do you really mean
"feature classes"?

What do you mean by "layers contents"?

In what environment do you need this list? Shell script? Python? C# VB? SQL?

What database are you using?  Which version?  What version and service pack
of ArcGIS?

- V
0 Kudos
WilliamCraft
MVP Regular Contributor
From the RDBMS directly, you can use the following queries:

To get a list of all tables registered with the geodatabase, use:

select table_name from sde.TABLE_REGISTRY;


To get a list of all layers (i.e., all GDB-registered tables which have a spatial column) within SDE, use:

select table_name from sde.LAYERS;


If you are wanting to know more spatial-specific information, the following Python script has worked for me (substitute your own info):

import os, subprocess, arcgisscripting, string, sys, os

gp = arcgisscripting.create(9.3)
gp.workspace = r"C:\Users\User1\AppData\Roaming\ESRI\ArcCatalog\test.sde"    

server = 'server'

def describeFeatures(sdeWorkspace,logWorkspace, logName,instance,user, psswd):
   
    logfile = open(os.path.join(logWorkspace, logName), 'w')

    datasets = gp.listdatasets("","")

    for dataset in datasets:

        gp.workspace = sdeWorkspace + os.sep + dataset

        for fc in gp.ListFeatureClasses():
               
                args = ['sdelayer', '-o', 'describe_long', '-l', str(fc) + ',SHAPE','-i', instance, \
                       '-u', user, '-p', psswd, '-s', server]

                p = subprocess.Popen(args, stdout=subprocess.PIPE)
                output = p.stdout.read()
               
                logfile.write(fc)
                logfile.write(output)
                logfile.write("\n")
               
                print fc, output
    logfile.close()

if __name__== "__main__":
   
    #connection to database

    sdeWorkspace = gp.workspace
    logName = "FeatureInfo.txt"
    logWorkspace = r"C:\Users\user1\Documents\python\DescribeFeatureClasses"
    instance = 'esri_metrorep'
    user = 'sde'
    psswd = 'sde'
    describeFeatures(sdeWorkspace,logWorkspace, logName,instance,user,psswd)
0 Kudos
AdrianaCalleja
New Contributor
From the RDBMS directly, you can use the following queries:

To get a list of all tables registered with the geodatabase, use:

select table_name from sde.TABLE_REGISTRY;


To get a list of all layers (i.e., all GDB-registered tables which have a spatial column) within SDE, use:

select table_name from sde.LAYERS;


If you are wanting to know more spatial-specific information, the following Python script has worked for me (substitute your own info):

import os, subprocess, arcgisscripting, string, sys, os

gp = arcgisscripting.create(9.3)
gp.workspace = r"C:\Users\User1\AppData\Roaming\ESRI\ArcCatalog\test.sde"    

server = 'server'

def describeFeatures(sdeWorkspace,logWorkspace, logName,instance,user, psswd):
   
    logfile = open(os.path.join(logWorkspace, logName), 'w')

    datasets = gp.listdatasets("","")

    for dataset in datasets:

        gp.workspace = sdeWorkspace + os.sep + dataset

        for fc in gp.ListFeatureClasses():
               
                args = ['sdelayer', '-o', 'describe_long', '-l', str(fc) + ',SHAPE','-i', instance, \
                       '-u', user, '-p', psswd, '-s', server]

                p = subprocess.Popen(args, stdout=subprocess.PIPE)
                output = p.stdout.read()
               
                logfile.write(fc)
                logfile.write(output)
                logfile.write("\n")
               
                print fc, output
    logfile.close()

if __name__== "__main__":
   
    #connection to database

    sdeWorkspace = gp.workspace
    logName = "FeatureInfo.txt"
    logWorkspace = r"C:\Users\user1\Documents\python\DescribeFeatureClasses"
    instance = 'esri_metrorep'
    user = 'sde'
    psswd = 'sde'
    describeFeatures(sdeWorkspace,logWorkspace, logName,instance,user,psswd)



Tanks a lot!
0 Kudos