<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Delete specific fields from all tables in EGDB in ArcGIS Pro Questions</title>
    <link>https://community.esri.com/t5/arcgis-pro-questions/delete-specific-fields-from-all-tables-in-egdb/m-p/1319366#M72168</link>
    <description>&lt;P&gt;So caveat - I'm am not a Python person but today, have been playing with ChatGPT to see how I can use it in GIS technologies.&amp;nbsp; Some examples show it can write arcpy scripts.&lt;/P&gt;&lt;P&gt;So I asked ChatGPT the following question - "Write an ArcGIS python script that loops through an enterprise geodatabase that deletes fields called ASSET_STATUS_DATE, PROP_DATE, ASSM_DATE, REMOV_DATE, BLOCK and MAP_ROTATION attribute fields common to any feature classes and non-spatial tables in the same enterprise geodatabase. If the feature class table or non-spatial table has one of those fields to delete, then create a copy of the feature class or non-spatial table and store it in a file geodatabase."&lt;/P&gt;&lt;P&gt;This is the code it provided in seconds...&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;import os&lt;/P&gt;&lt;P&gt;# Set the workspace to your enterprise geodatabase&lt;BR /&gt;arcpy.env.workspace = r"C:\Path\To\Your\EnterpriseGeodatabase.sde" # Update with your actual workspace path&lt;/P&gt;&lt;P&gt;# List of common attribute fields to be deleted&lt;BR /&gt;fields_to_delete = ["ASSET_STATUS_DATE", "PROP_DATE", "ASSM_DATE", "REMOV_DATE", "BLOCK", "MAP_ROTATION"]&lt;/P&gt;&lt;P&gt;# Path to the file geodatabase where copies will be created&lt;BR /&gt;output_fgdb = r"C:\Path\To\Your\OutputFileGeodatabase.gdb" # Update with your actual path&lt;/P&gt;&lt;P&gt;# Create a file geodatabase if it doesn't exist&lt;BR /&gt;if not arcpy.Exists(output_fgdb):&lt;BR /&gt;arcpy.CreateFileGDB_management(os.path.dirname(output_fgdb), os.path.basename(output_fgdb))&lt;/P&gt;&lt;P&gt;# Loop through feature classes&lt;BR /&gt;for fc in arcpy.ListFeatureClasses():&lt;BR /&gt;has_deleted_fields = False&lt;BR /&gt;fields_deleted = []&lt;/P&gt;&lt;P&gt;for field in fields_to_delete:&lt;BR /&gt;if arcpy.ListFields(fc, field):&lt;BR /&gt;arcpy.DeleteField_management(fc, field)&lt;BR /&gt;fields_deleted.append(field)&lt;BR /&gt;has_deleted_fields = True&lt;/P&gt;&lt;P&gt;# Create a copy if fields were deleted&lt;BR /&gt;if has_deleted_fields:&lt;BR /&gt;output_fc = os.path.join(output_fgdb, fc)&lt;BR /&gt;arcpy.Copy_management(fc, output_fc)&lt;BR /&gt;print(f"Created copy of '{fc}' in '{output_fgdb}' with fields deleted: {fields_deleted}")&lt;/P&gt;&lt;P&gt;# Loop through tables&lt;BR /&gt;for table in arcpy.ListTables():&lt;BR /&gt;has_deleted_fields = False&lt;BR /&gt;fields_deleted = []&lt;/P&gt;&lt;P&gt;for field in fields_to_delete:&lt;BR /&gt;if arcpy.ListFields(table, field):&lt;BR /&gt;arcpy.DeleteField_management(table, field)&lt;BR /&gt;fields_deleted.append(field)&lt;BR /&gt;has_deleted_fields = True&lt;/P&gt;&lt;P&gt;# Create a copy if fields were deleted&lt;BR /&gt;if has_deleted_fields:&lt;BR /&gt;output_table = os.path.join(output_fgdb, table)&lt;BR /&gt;arcpy.Copy_management(table, output_table)&lt;BR /&gt;print(f"Created copy of '{table}' in '{output_fgdb}' with fields deleted: {fields_deleted}")&lt;/P&gt;&lt;P&gt;print("Script completed.")&lt;/P&gt;&lt;P&gt;It then adds - "This script will delete the specified fields from the feature classes and non-spatial tables in the enterprise geodatabase and then create copies of those datasets with the specified fields removed in the specified file geodatabase (output_fgdb). Make sure to update the paths (arcpy.env.workspace, output_fgdb) as needed for your specific use case."&lt;/P&gt;&lt;P&gt;I'm curious from Python folks if this makes sense.&amp;nbsp; If you do try the code, let me know how it works (or does not work) for you.&lt;/P&gt;</description>
    <pubDate>Wed, 16 Aug 2023 21:34:29 GMT</pubDate>
    <dc:creator>Robert_LeClair</dc:creator>
    <dc:date>2023-08-16T21:34:29Z</dc:date>
    <item>
      <title>Delete specific fields from all tables in EGDB</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/delete-specific-fields-from-all-tables-in-egdb/m-p/1318896#M72113</link>
      <description>&lt;P&gt;&lt;EM&gt;ArcGIS Pro 2.6.8; Oracle 18c 10.7.1 EGDB&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;I have 300 tables in a production enterprise geodatabase. When I say&amp;nbsp;&lt;EM&gt;tables&amp;nbsp;&lt;/EM&gt;I mean &lt;EM&gt;feature classes &lt;/EM&gt;and&lt;EM&gt; tables&lt;/EM&gt;.&lt;/P&gt;&lt;P&gt;Some (but not all) of the tables have fields that need to be deleted. Fields:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;ASSET_STATUS_DATE&lt;/LI&gt;&lt;LI&gt;PROP_DATE&lt;/LI&gt;&lt;LI&gt;ASSM_DATE&lt;/LI&gt;&lt;LI&gt;REMOV_DATE&lt;/LI&gt;&lt;LI&gt;BLOCK&lt;/LI&gt;&lt;LI&gt;MAP_ROTATION&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;Question:&lt;BR /&gt;What is a simple, safe way to delete the fields programmatically? For example, a model or Python script that:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Loops through all GDB tables.&lt;/LI&gt;&lt;LI&gt;If the table has one of the fields we want to delete, create a copy (a backup) of the FC in a pre-made file geodatabase.&lt;/LI&gt;&lt;LI&gt;Delete the fields from the FC.&lt;BR /&gt;&lt;EM&gt;Note: I don't need to check if the fields are empty, etc.&lt;/EM&gt;&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;What mechanism do you recommend for that use case?&lt;/P&gt;&lt;P&gt;Thanks.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2023 13:53:10 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/delete-specific-fields-from-all-tables-in-egdb/m-p/1318896#M72113</guid>
      <dc:creator>Bud</dc:creator>
      <dc:date>2023-08-16T13:53:10Z</dc:date>
    </item>
    <item>
      <title>Re: Delete specific fields from all tables in EGDB</title>
      <link>https://community.esri.com/t5/arcgis-pro-questions/delete-specific-fields-from-all-tables-in-egdb/m-p/1319366#M72168</link>
      <description>&lt;P&gt;So caveat - I'm am not a Python person but today, have been playing with ChatGPT to see how I can use it in GIS technologies.&amp;nbsp; Some examples show it can write arcpy scripts.&lt;/P&gt;&lt;P&gt;So I asked ChatGPT the following question - "Write an ArcGIS python script that loops through an enterprise geodatabase that deletes fields called ASSET_STATUS_DATE, PROP_DATE, ASSM_DATE, REMOV_DATE, BLOCK and MAP_ROTATION attribute fields common to any feature classes and non-spatial tables in the same enterprise geodatabase. If the feature class table or non-spatial table has one of those fields to delete, then create a copy of the feature class or non-spatial table and store it in a file geodatabase."&lt;/P&gt;&lt;P&gt;This is the code it provided in seconds...&lt;/P&gt;&lt;P&gt;import arcpy&lt;BR /&gt;import os&lt;/P&gt;&lt;P&gt;# Set the workspace to your enterprise geodatabase&lt;BR /&gt;arcpy.env.workspace = r"C:\Path\To\Your\EnterpriseGeodatabase.sde" # Update with your actual workspace path&lt;/P&gt;&lt;P&gt;# List of common attribute fields to be deleted&lt;BR /&gt;fields_to_delete = ["ASSET_STATUS_DATE", "PROP_DATE", "ASSM_DATE", "REMOV_DATE", "BLOCK", "MAP_ROTATION"]&lt;/P&gt;&lt;P&gt;# Path to the file geodatabase where copies will be created&lt;BR /&gt;output_fgdb = r"C:\Path\To\Your\OutputFileGeodatabase.gdb" # Update with your actual path&lt;/P&gt;&lt;P&gt;# Create a file geodatabase if it doesn't exist&lt;BR /&gt;if not arcpy.Exists(output_fgdb):&lt;BR /&gt;arcpy.CreateFileGDB_management(os.path.dirname(output_fgdb), os.path.basename(output_fgdb))&lt;/P&gt;&lt;P&gt;# Loop through feature classes&lt;BR /&gt;for fc in arcpy.ListFeatureClasses():&lt;BR /&gt;has_deleted_fields = False&lt;BR /&gt;fields_deleted = []&lt;/P&gt;&lt;P&gt;for field in fields_to_delete:&lt;BR /&gt;if arcpy.ListFields(fc, field):&lt;BR /&gt;arcpy.DeleteField_management(fc, field)&lt;BR /&gt;fields_deleted.append(field)&lt;BR /&gt;has_deleted_fields = True&lt;/P&gt;&lt;P&gt;# Create a copy if fields were deleted&lt;BR /&gt;if has_deleted_fields:&lt;BR /&gt;output_fc = os.path.join(output_fgdb, fc)&lt;BR /&gt;arcpy.Copy_management(fc, output_fc)&lt;BR /&gt;print(f"Created copy of '{fc}' in '{output_fgdb}' with fields deleted: {fields_deleted}")&lt;/P&gt;&lt;P&gt;# Loop through tables&lt;BR /&gt;for table in arcpy.ListTables():&lt;BR /&gt;has_deleted_fields = False&lt;BR /&gt;fields_deleted = []&lt;/P&gt;&lt;P&gt;for field in fields_to_delete:&lt;BR /&gt;if arcpy.ListFields(table, field):&lt;BR /&gt;arcpy.DeleteField_management(table, field)&lt;BR /&gt;fields_deleted.append(field)&lt;BR /&gt;has_deleted_fields = True&lt;/P&gt;&lt;P&gt;# Create a copy if fields were deleted&lt;BR /&gt;if has_deleted_fields:&lt;BR /&gt;output_table = os.path.join(output_fgdb, table)&lt;BR /&gt;arcpy.Copy_management(table, output_table)&lt;BR /&gt;print(f"Created copy of '{table}' in '{output_fgdb}' with fields deleted: {fields_deleted}")&lt;/P&gt;&lt;P&gt;print("Script completed.")&lt;/P&gt;&lt;P&gt;It then adds - "This script will delete the specified fields from the feature classes and non-spatial tables in the enterprise geodatabase and then create copies of those datasets with the specified fields removed in the specified file geodatabase (output_fgdb). Make sure to update the paths (arcpy.env.workspace, output_fgdb) as needed for your specific use case."&lt;/P&gt;&lt;P&gt;I'm curious from Python folks if this makes sense.&amp;nbsp; If you do try the code, let me know how it works (or does not work) for you.&lt;/P&gt;</description>
      <pubDate>Wed, 16 Aug 2023 21:34:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-pro-questions/delete-specific-fields-from-all-tables-in-egdb/m-p/1319366#M72168</guid>
      <dc:creator>Robert_LeClair</dc:creator>
      <dc:date>2023-08-16T21:34:29Z</dc:date>
    </item>
  </channel>
</rss>

