Sobes.tech
Senior

What acts as the Primary Key in a table with fields name, surname, age, gender?

sobes.tech AI

Answer from AI

In a table with fields such as first name, last name, age, and gender, it is not recommended to use these fields directly as the Primary Key, as they do not guarantee the uniqueness of records. For example, different people can have the same first and last name, and age and gender do not make the record unique.

To uniquely identify records, a separate field is usually added, such as id with a unique value (e.g., auto-increment or UUID). If a composite key is used, a combination of several fields can be taken, but in this case, it is unreliable.

Example of creating a table with a primary key:

CREATE TABLE persons (
  id SERIAL PRIMARY KEY,
  first_name VARCHAR(50),
  last_name VARCHAR(50),
  age INT,
  gender CHAR(1)
);

Thus, the Primary Key is a unique identifier for a record, which in this case is best implemented as a separate field.

What acts as the Primary Key in a table with fields… - sobes.tech