This question was asked in my viva.


Each Foreign key must exist as a primary key.
Foreign keys values can change over time..


According to me the second statement is false.But he said that they can change values...Is it so???

Recommended Answers

All 2 Replies

Not really, if the foreign key value changes, it loses the relational link to the primary key. So you then lose the integrity of the information as the row values will link to another primary key value of different data, or nothing if it doesn't exist causing an error.

You can physically change the foreign key value to match to another primary key value, when modifying a mistake made, e.g. the foreign key's record meaning to match a different primary key's record.

E.g. Employees and Employee Scores.
Employee101 scored at 55%
Employee102 scored at 60%

Say that these have (somehow!) mixed around in the database, so you have to change the foreign key EmployeeID of Employee102 (in the Scored table), to the EmployeeID of Employee101 so that Employeee101 scored 60% (and vice versa otherwise Employee101 scores both 55% and 60%).

This type of mistake wouldn't really happen unless you coded the front end to mess with the values input into the system.

thank you.:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.