Relationship Notes

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

Relationship

It is a link between two table using related and duplicate values.

Requirement for the relationship

❖ Both tables are needed to create relationship and same fields are in the
both tables.

Primary Key

[Parent Table] [Child Table]

Foreign Key
It is a field that is related to the primary key of primary table in relationship.
Primary Table (Parent table)
The table contain primary key it call as a primary table.
Related table (Child table)
The related contain foreign key it call as a related table.
❖ The data type of both primary key and foreign key must be same.

Relationship types
Relationship type depends on how to relate columns are defined. There are 3
types.

1. One to One
2. One to Many
3. Many to Many

ICT NVQ Level 4 | Hasitha Dilshan Galagedara, Instructor at VTC-Dehiwala 1


1. One To One [|------|]
In this type primary key field in course table has only one matching record in table of students.

Foreign key field in student table has matching records in course table. In this type primary key
and foreign key have primary key.

Co_No Co_No

001 001

002 002

Primary Table Course Student


Table Table

Related Table

2. One to Many [|------ ∞]


This is the most common type in relationship.

In this type of relationship primary key field in course table can have many matching records in
foreign key table in student table. But a data in student table can have one matching record in
course table.

In this type primary table Have primary table have primary key and there is no primary key for
the foreign key in related table.

Co_No Co_No
001 001

002 001

001

002
Primary Table
002
Related Table

ICT NVQ Level 4 | Hasitha Dilshan Galagedara, Instructor at VTC-Dehiwala 2


3. Many to Many

In this type a data in course table have many matching records in students table and a data in student table can
have many matching records.

In this type of relationship both primary key and foreign key are not in primary and related table.

Order_ID Order_ID
001 001

001 001

001

Relationship Settings
Edit Relationship – enforce referential Integrity

1. You can’t enter a value for the foreign key field in the related table that does not existing in the
primary key of primary table.
2. But you can enter a null value for the foreign key field.
3. So when entering data first you enter data for primary table. Then enter data for the related
table.
4. You can’t delete record from primary table, if matching record in related table.
5. You can’t change the record from primary table that matching record existing in related table.

Cascade update related field


If you change a value in primary key of primary table access automatically update foreign key values.

Cascade deleted related record


If you delete a record in primary table access automatically deleted the all related table of related
records.

FORM
The form is a graphical interface, use to add data or view data or modify data,
The form views the data of one record in table at once.

ICT NVQ Level 4 | Hasitha Dilshan Galagedara, Instructor at VTC-Dehiwala 3


Query
Query is small tables create by selecting records from a table or more table.
Query can also perform calculation and display the result.

Query criteria

1. Text criteria
a. Matching Text

Field Status
Table Employee
Criteria “Doctor”

b. Use OR

Field Status
Table Employee
Criteria “Doctor”
OR “Teacher”

c. Use ‘Not’

Field Status
Table Employee
Criteria Not “Teacher”

d. Not in

Criteria Not in (“Teacher”, “Doctor”)

e. Like

Field Emplooye_Name
Criteria Like “P”

f. Like “P*” = P අකුරින් පටන්ගන්න සියළුම නම්


g. Like “*P” = p අකුරින් අවසන් වන සියළුම නම්
h. Like “[A-G]* = A සිට G වනතෙක් අකුරුවලින් පටන්ගන්න සියළුම නම්

ICT NVQ Level 4 | Hasitha Dilshan Galagedara, Instructor at VTC-Dehiwala 4


2. Number Filter
a. Greater than or equal

Field Payment
Table Student Details
Criteria >=13000

b. Use Between

Criteria >8000 and <11000

c. OR

Criteria >8000 OR >11000

3. Date Filter
a. Use #Date#

Field DOB
Table Student
Criteria # 04 / 04 / 2007 #

b. Use ‘Date’

Criteria = Date ()

4. Finding Empty Field

Field Emp_Name
Table Details
Criteria Is null

ICT NVQ Level 4 | Hasitha Dilshan Galagedara, Instructor at VTC-Dehiwala 5

You might also like