Grades 6–8 · Computing
How do IDs connect records in different database tables?
A relational database organizes information in tables. A row is a record, and a column names a field stored for each record. An identifier distinguishes a record from others. Unlike a row number in a display, an ID can remain the same when the table is sorted differently.
In the diagramA shared ID connects related recordsSitesObservationsIDNameRowSite IDValueS1PondS2HillR17R25R39R1 → S1 → PondAn ID is a relationship key, not a row position.
The site table contains S1 for Pond and S2 for Hill. The observation table stores its own record labels, site IDs and measured values. Observation R1 has site ID S1 and value seven. Matching S1 to the site table connects that observation with Pond.
The site ID in an observation acts as a foreign key: a reference to a key in another table. R3 also references S1, so multiple observations can connect to the same site. That is a one-to-many relationship from sites to observations. The observation’s value remains its own field, not part of the site ID.
Storing the site name separately avoids repeating it in every observation record. A database can enforce that each referenced site ID exists, preserving the stated relationship. This checks a structural connection, not whether a measurement is true. The diagram highlights matching keys so that the relationship remains clear even if row positions or names change.
About this explanation
Starting knowledge: Read rows and columns in a small table and distinguish an identifier from a measured value.
Sources
- PostgreSQL Global Development Group — Foreign keys and referential integrity