Providing a unique key for a table

If a table that has no unique column values, you can provide a unique identifier by using ROWID columns or identity columns to store unique values for each row in a table.

Procedure

To provide a unique identifier for a table that does not already have a column with unique values, use the following approaches.

  • Add a column with the data type ROWID or an identity column. ROWID columns and identity columns contain a unique value for each row in the table.
  • You can define the column as GENERATED ALWAYS, which means that you cannot insert values into the column, or GENERATED BY DEFAULT, which means that Db2 generates a value if you do not specify one.
  • If you define the ROWID or identity column as GENERATED BY DEFAULT, you must also define a unique index that includes only that column to guarantee uniqueness.
  • Start of changeFL 508 Another option is to generate UUID values. A universally unique Identifier (UUID) is a 128-bit label used to uniquely identify objects in computer systems, without central authority. UUIDs are commonly used in microservices and cloud services. For more information, see Universally unique identifier (UUID) values in Db2 for z/OS.End of change