Those columns are used to link together the tables and their entities. Giving you a specific scenario, just think of the following content,
Account
id | name | ...
1 | ABCD | ...
2 | EFGH | ...
Sessions
id | account_id | ...
1 | 1 | ...
2 | 43 | ...
3 | 3 | ...
4 | 1 | ...
5 | 2 | ...
For example, in the states where you want to show all the sessions linked to a specific account from both the tables, you would use the ID from Account and Account_Id from Sessions table to "
JOIN
" them together. In SQL JOIN, you specify which records to
JOIN
based on which criteria —
the columns.
Thus, getting something like this,
Account.id | Sessions.id | name | ...
1 | 1 | ABCD | ...
1 | 4 | ABCD | ...
Then further stuff is your own logic to use the data, how? That is all upto you, basically this is done on the tables that have been
normalized. You remove a few common anomalies from the tables, and you remove some data redundancies. That step results in more than 1, 2 or even 3 tables sometimes. Thus getting the data back requires you to JOIN the tables. These columns —
account.id
,
sessions.account_id
— act as the pivot points for your tables to be
JOIN
ed at.
For a better explanation of how to JOIN the tables in SQL, please read the following articles,
Visual Representation of SQL Joins[
^]
Types of Join in SQL Server[
^]
Database normalization - Wikipedia[
^]