0% found this document useful (0 votes)
2 views9 pages

Primary Key Vs Foreign Key

Uploaded by

mounassif.fst
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views9 pages

Primary Key Vs Foreign Key

Uploaded by

mounassif.fst
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

Copyright© 2023 Mohammed Abu-Hadhoud

ProgrammingAdivces.com MBA, PMOC, PgMP®, PMP®, PMI-RMP®, CM, ITILF, MCPD, MCSD
26+ years of experience
Copyright© 2023 Mohammed Abu-Hadhoud
ProgrammingAdivces.com MBA, PMOC, PgMP®, PMP®, PMI-RMP®, CM, ITILF, MCPD, MCSD
26+ years of experience
Primary Key
vs
Foreign Key

Copyright© 2023 Mohammed Abu-Hadhoud


ProgrammingAdivces.com MBA, PMOC, PgMP®, PMP®, PMI-RMP®, CM, ITILF, MCPD, MCSD
26+ years of experience
In RDBMS.
Data that is stored in an organized fashion in tables containing rows and columns along with relations between
these tables.

Table/Entity Set

Column/Field/Attribute
Employees Table
Row/Entity/Record
ID FirstName LastName Gender Birthdate Salary DepartmentID

1 Mohammed Abu‐Hadhoud M 6/11/1977 5000 1

2 Ali Zaher M 5/7/1990 3000 2 Departments Table


ID Name Location
3 Lubna Aqel F 5/5/2000 500 1

1 IT Amman
5 Fadi Khalil M 6/6/1980 1400 4

2 Finance Amman
6 Maha Majed M 7/7/2001 300 3

3 HR UAE
7 Omar Ali M 6/6/1977 2000 1

4 Marketing Qatar
8 Huda Omar F 4/2/1990 1000 1

Copyright© 2023 Mohammed Abu-Hadhoud


ProgrammingAdivces.com MBA, PMOC, PgMP®, PMP®, PMI-RMP®, CM, ITILF, MCPD, MCSD
26+ years of experience
Primary Key vs Foreign Key

Primary Key
Employees Table
ID FirstName LastName Gender Birthdate Salary DepartmentID
Primary Key
1 Mohammed Abu‐Hadhoud M 6/11/1977 5000 1

2 Ali Zaher M 1/1/2000 500 2 Departments Table


ID Name Location
3 Lubna Aqel F 5/5/2000 500 1

1 IT Amman
5 Fadi Khalil M 6/6/1980 1400 4

2 Finance Amman
6 Maha Majed M 7/7/2001 300 3

3 HR UAE
7 Omar Ali M 6/6/1977 2000 1

4 Marketing Qatar
8 Huda Omar F 4/2/1990 1000 1

Foreign Key

Copyright© 2023 Mohammed Abu-Hadhoud


ProgrammingAdivces.com MBA, PMOC, PgMP®, PMP®, PMI-RMP®, CM, ITILF, MCPD, MCSD
26+ years of experience
Primary Key
• A primary key is a column or set of columns in a relational database table
that uniquely identifies each row or record in the table.
• It is a unique identifier for each record and serves as a reference point
for other tables that have a relationship with the table in question.

• Each table in a relational database must have a primary key, and it should
be a non-null value that is unique and stable over time.

• Primary Key should not be changed.

Copyright© 2023 Mohammed Abu-Hadhoud


ProgrammingAdivces.com MBA, PMOC, PgMP®, PMP®, PMI-RMP®, CM, ITILF, MCPD, MCSD
26+ years of experience
Foreign Key
• A foreign key, on the other hand, is a column or set of columns in a table
that refers to the primary key of another table.

• It establishes a relationship between two tables, allowing data to be


shared and linked between them.

• The foreign key ensures that referential integrity is maintained by


ensuring that any value in the foreign key column must exist in the primary
key column of the related table.

Copyright© 2023 Mohammed Abu-Hadhoud


ProgrammingAdivces.com MBA, PMOC, PgMP®, PMP®, PMI-RMP®, CM, ITILF, MCPD, MCSD
26+ years of experience
Summary
• In summary, a primary key uniquely identifies a record in a table, while a
foreign key establishes a relationship between two tables by referencing
the primary key of another table.

Copyright© 2023 Mohammed Abu-Hadhoud


ProgrammingAdivces.com MBA, PMOC, PgMP®, PMP®, PMI-RMP®, CM, ITILF, MCPD, MCSD
26+ years of experience
Copyright© 2023 Mohammed Abu-Hadhoud
ProgrammingAdivces.com MBA, PMOC, PgMP®, PMP®, PMI-RMP®, CM, ITILF, MCPD, MCSD
26+ years of experience

You might also like