Does the OBJECTID in an Oracle Geodatabase table have a primary key constraint, by default?
By default, yes, it normally is unless someone overrode that and designed the table differently.
Is this an ArcSDE database? There may also be GlobalID fields that act as primary keys across multiple databases with relationship tables, so that may add some complications.
You are correct; there can only be one primary key. However, with the right permissions, you should be able to edit which field is acting as a primary key if you needed to.
I think the answer is no. The OBJECTID
in an Oracle geodatabase table does not have a primary key constraint
, by default.
When I query an Oracle geodatabase table to return the column that has a primary key constraint
, the OBJECTID
is not returned/flagged:
SELECT
cols.table_name,
cols.column_name,
cols.position,
cons.status,
cons.owner
FROM
all_constraints cons,
all_cons_columns cols
WHERE
cols.table_name = 'ROAD'
AND cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
The result set is empty:
+------------+-------------+----------+--------+-------+
| TABLE_NAME | COLUMN_NAME | POSITION | STATUS | OWNER |
+------------+-------------+----------+--------+-------+
| | | | | |
+------------+-------------+----------+--------+-------+
In contrast, I've created a dummy table with a primary key constraint
:
CREATE TABLE A_TEST
(
P_ID int NOT NULL PRIMARY KEY
)
When I run the query on it, the field with the primary key is returned, as expected:
+------------+-------------+----------+---------+-------+
| TABLE_NAME | COLUMN_NAME | POSITION | STATUS | OWNER |
+------------+-------------+----------+---------+-------+
| A_TEST | P_ID | 1 | ENABLED | ENG |
+------------+-------------+----------+---------+-------+
As far as I can tell, this proves that the OBJECTID
in an Oracle geodatabase table does not have a primary key constraint.
Just because the OBJECTID
is similar to a primary key (has a unique not-nullable index
) it doesn't mean that it actually has a primary key constraint
.
No, OBJECTID
does not have a database level Primary Key constraint.
OBJECTID
is managed directly by ArcGIS, not by the underlying database. Esri Geodatabases do not have database managed keys, and it would be unwise to apply your own due to the ArcGIS system managing all geodatabase relationships itself.
See my answer to your other question Can primary keys and foreign keys be used in enterprise geodatabases?
Please also note that the field name does not always have to be OBJECTID
- it is possible to have a different field name, and these field names are managed through a separate table in your geodatabase. From What is an ObjectID?:
- An ArcGIS-maintained ObjectID field is automatically added to any table created using ArcGIS.
- If you register a table with the geodatabase that does not have a qualifying field, the geodatabase adds another field to the table that meets the requirements of an ObjectID and names it OBJECTID. If your table already contains a column that is named OBJECTID, the geodatabase adds a column named OBJECTID_1.
- If you register a table with the geodatabase and the table does contain a qualifying field (integer, not null), the existing column can be used as the ObjectID.
Also see What's the best way to get the OBJECTID name?
In my local geodatabase I have a table called SDE_table_registry
which has a column rowid_column
listing the name of the OBJECTID
equivalent field in each of my tables (although I only have 2 feature classes in my geodatabase and they both have the standard OBJECTID
field name).