Select to view content in your preferred language

Best practice to set a table's PRIMARY KEY in a MS SQL Enterprise Geodatabase

159
0
06-28-2024 01:19 PM
TylerT
by
Occasional Contributor III

Using geoaccessor method to_table() and to_featureclass()

TylerT_0-1719604987205.png

do not set a PRIMARY KEY (PK) in the enterprise geodatabase.  A PK is required to reflect tables as orm declarative tables with SQLAlchemy's automap_base.  This is why I want to set a PK.

Is there any risk to the geodatabase inner workings to set a PK by passing the following SQL:

 

 

ALTER TABLE {tbl} ALTER COLUMN {pk} {dtype} NOT NULL
ALTER TABLE {tbl} ADD PRIMARY KEY({pk})

 

 

This SQL runs without error, and following the PK set, sqlalchemy is much happier.  I'm curious if there are any unintended consequences to setting PK with third party tools such as SQL (i.e. outside of ArcGIS API).

If this is NOT recommended, does ArcGIS Pro or Arcpy have a tool to set PK in the EGDB (not to be confused with relationship class PKs), or do you have any other suggestions?

Thank you,

Tyler

0 Kudos
0 Replies