Sobes.tech
Junior — Middle

Can you name the main types of keys used in relational databases?

sobes.tech AI

Answer from AI

Main types of keys in relational databases:

  • Primary Key — a unique identifier for a record in a table. Cannot contain NULL and must be unique.
  • Foreign Key — a field or set of fields that references the primary key of another table, establishing a relationship between tables.
  • Unique Key — guarantees the uniqueness of values in a column or set of columns, allows NULLs (in some DBMS).
  • Surrogate Key — an artificial key, usually an auto-incremented number, without business meaning.
  • Composite Key — a key consisting of multiple columns that together ensure uniqueness.

An example in Go using a structure to describe keys is not necessary, as this is a database concept, but when working with ORM, it is important to specify keys correctly.