Skip to content

Instantly share code, notes, and snippets.

@BGranberg
Created May 23, 2012 22:28
Show Gist options
  • Save BGranberg/2778230 to your computer and use it in GitHub Desktop.
Save BGranberg/2778230 to your computer and use it in GitHub Desktop.
Truncate and Load ArcSDE 10 Table.py - Copy and paste this script into notepad. Then set the sourceDataFullPath and updateDataFullPath variables appropriately and save the file. Schemas have to match exactly. Also, this script references an SDE connection
import arcpy
arcpy.env.overwriteOutput = True
def fcUpdate(srcTable, tarTable):
tarTableView = arcpy.MakeTableView_management(tarTable,'targetTable')
srcTableView = arcpy.MakeTableView_management(srcTable,'sourceTable')
arcpy.DeleteRows_management(tarTableView)
arcpy.Append_management(srcTable, tarTable, 'TEST','#','#')
arcpy.Delete_management(tarTableView)
arcpy.Delete_management(srcTableView)
print "Success (" + srcTable + " uploaded)"
#Begin Main
sourceDataFullPath = r"C:\temp\yourgeodatabase.gdb\yourtablenameall"
updateDataFullPath = r"Database Connections\yourConnectionFileName\SDEDatabaseName.User.TableName"
if arcpy.GetCount_management(sourceDataFullPath) > 0:
fcUpdate(sourceDataFullPath, updateDataFullPath)
else:
print "No features found in " + srcTable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment