How to add and remove GlobalID columns


This sample can be used to add or remove globalid columns to feature classes or tables in a geodatabase. The sample code will error when executed against non-geodatabase data sources such as shapefiles. The add_globalid routine also requires the table or feature class to be empty (no rows) for personal geodatabases. This routine will succeed for tables or feature classes with data when executed on SDE geoedatabases.

How to use

  1. Start ArcCatalog and Paste the code into VBA.
  2. Connect to the geodatabase and select the table for featureclass.
  3. Run either of the routines to add or delete a globalid column.
[VBA]
Sub add_globalid()
    
    Dim pGxApp As IGxApplication
    Dim pgxobj As IGxObject
    Dim pname As IName
    Dim ptable As ITable
    Dim pCSE3 As IClassSchemaEdit3
    
    '++ Get the selected table and add the globalid column
    Set pGxApp = Application
    Set pgxobj = pGxApp.SelectedObject
    Set pname = pgxobj.InternalObjectName
    Set ptable = pname.Open
    Set pCSE3 = ptable
    pCSE3.AddGlobalID "Globalid"
    
End Sub

Sub delete_globalid()
    
    Dim pGxApp As IGxApplication
    Dim pgxobj As IGxObject
    Dim pname As IName
    Dim ptable As ITable
    Dim pCSE3 As IClassSchemaEdit3
    
    '++ Get the selected table and delete the globalid column
    Set pGxApp = Application
    Set pgxobj = pGxApp.SelectedObject
    Set pname = pgxobj.InternalObjectName
    Set ptable = pname.Open
    Set pCSE3 = ptable
    pCSE3.DeleteGlobalID
    
End Sub