Database / Mnesia basics Interview questions
What is the primary key in a Mnesia table?
The primary key of a Mnesia table is always its first declared attribute — there's no separate syntax
to mark a different field as the key the way some databases let you designate an arbitrary column. Every
lookup by mnesia:read/1 or mnesia:dirty_read/1 is keyed on this first field.
-record(person, {id, name, age}). %% id is the primary key mnesia:read({person, 1}). %% looks up by id = 1
On a set or ordered_set table, this key must be unique — writing a new
record with an existing key's value overwrites the old one. On a bag table, the same key value
can appear across multiple distinct records, since uniqueness isn't enforced for that table type.
More Related questions...