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:

  1. From the UI: Create new table, Import from Excel, or Import from CSV

    1. NocoDB creates an ID [datatype: Integer] system field by default when it creates the table. This field is the primary key.
    2. NocoDB also adds the system fields created-at and updated-at by default.
  2. Connect to an existing external database

    1. NocoDB keeps the existing primary key field of the table. NocoDB does not add a new ID field.
    2. NocoDB does not add the system fields created-at and updated-at by default.
  3. Import from Airtable

    1. The Airtable record ID is the primary key for imported records. It maps to the field ncRecordId [datatype: varchar].
    2. If you add a new record after migration without a value for ncRecordId, NocoDB inserts an automatically generated string.
    3. NocoDB stores a hash value of the full record in the system field ncRecordHash.
    4. NocoDB does not add the system fields created-at and updated-at by default.
  4. Create a new table with the SDK or API

    1. NocoDB does not add a default primary key field. You must set it when you create the table, with the attribute pk: true.

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

Latest product updates?See Changelog
Stay in the loop? Follow us onLinkedInLinkedInYouTubeYouTubeXX