Loading...
In our database chapter both keys are about identifying records and I keep swapping their definitions in tests. Can someone explain with a simple example?
A primary key uniquely identifies each row within its own table, and it cannot be null or duplicated. For example, in a Students table, RollNo can be the primary key because every student has a unique roll number. A foreign key is a column in one table that refers to the primary key of another table, creating a link between them. For example, a Marks table might have a RollNo column that is a foreign key pointing to RollNo in the Students table, so each mark record is tied to a real student. The foreign key enforces referential integrity, meaning you cannot enter a RollNo in Marks that does not exist in Students. In short, a primary key identifies records within a table, while a foreign key connects two tables together.
Sign in as a tutor to answer this doubt.