If you use the FOREIGN KEY to protect the score
value in the pupils
table, you still need to have a score column in pupils
. You can't have a FOREIGN KEY relationship without columns in both tables.
The only advantage of the FOREIGN KEY is that it would let you restrict the values allowed in the score
column to integers between 1 and 100. The same thing can be done, however, with a CHECK constraint on the column, without the need for the extra table.
If you use the FOREIGN KEY, your DDL would look like this:
CREATE TABLE pupils (
id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
name TEXT, surname TEXT, address TEXT, score INTEGER REFERENCES score(percentage)
);
Note that the score column is still there.
In this case the FOREIGN KEY approach adds an whole table and two indexes that have to be maintained. Much more efficient to use one table and a CHECK constraint.