# Table Relationships

In a database, tables are often related to each other; for example, one table may hold information about companies, and another table may hold information about the people who work at the companies.

A Parent Table is the primary or controlling table in the relationship - for example, the Company table is the parent of the Person table.

A Child Table has one or more rows that are related to the parent table - for example, the Person table is a child of the Company table.

The Primary Key in a table identifies each record in the table uniquely. It is often an integer; record 1 has the number 1, etc. However, there is a wide variety of ways that the primary key can be generated.

The Foreign Key is used in a child table to specify which row in the parent table the child belongs to.

Table relationships control how a child record is related to a parent record. Inaport will normally fill in the Primary Key and Foreign Key entries for the Relationships tab; if you are using a table that it does not know about, you must fill them in.

For example, in Sage CRM there is a Company table, and a Person table. The Person table is a child of the Company table; rows in the person table are related to a row in the Company table

In the Company table, the primary key is the field comp_companyid.

In the Person table, the primary key is pers_personid and the foreign key is pers_companyid.

comp_companyid (Primary) | comp_name
--- | ---
1 | Acme Corp
2 | Mega Corp

pers_personid (Primary) | pers_companyid (Foreign) | pers_name
--- | --- | ---
1 | 1 | John Smith
2 | 2 | Fred Bloggs
3 | 2 | John Smith
4 | 1 | Bob Jones

In the Person table above, John Smith in row 1 works for Acme Corp; John Smith in row 3 works for Mega Corp; this can be established by looking at the foreign key column (pers_companyid), which shows the value for the related row in the Company table.