Primary Key
A primary key is a special field in a database table. It identifies each record in the table uniquely. NocoDB uses the primary key internally for all operations on a record.
Primary Key in NocoDB
The primary key that NocoDB uses depends on how the table was created:
-
From the UI: Create new table, Import from Excel, or Import from CSV
- NocoDB creates an
ID[datatype: Integer] system field by default when it creates the table. This field is the primary key. - NocoDB also adds the system fields
created-atandupdated-atby default.
- NocoDB creates an
-
Connect to an existing external database
- NocoDB keeps the existing
primary keyfield of the table. NocoDB does not add a new ID field. - NocoDB does not add the system fields
created-atandupdated-atby default.
- NocoDB keeps the existing
-
Import from Airtable
- The Airtable record ID is the primary key for imported records. It maps to the field
ncRecordId[datatype: varchar]. - If you add a new record after migration without a value for
ncRecordId, NocoDB inserts an automatically generated string. - NocoDB stores a hash value of the full record in the system field
ncRecordHash. - NocoDB does not add the system fields
created-atandupdated-atby default.
- The Airtable record ID is the primary key for imported records. It maps to the field
-
Create a new table with the SDK or API
- NocoDB does not add a default primary key field. You must set it when you create the table, with the attribute
pk: true.
- NocoDB does not add a default primary key field. You must set it when you create the table, with the attribute
FAQ
What if Primary Key was missing?
In NocoDB, a table can have no primary key. This happens when the table is created externally, or through the SDK or API without a primary key. You can add new records to this table. You cannot update or delete records, because no unique identifier points to each record.
Can I change the Primary Key to another field within tables?
You cannot change the Primary Key from the NocoDB UI. Change it directly in the database, and then run meta sync manually.
Last updated on