I have 2 tables as you will see in my posgresql code below. The first table students has 2 columns, one for student_name and the other student_id which is the primary key. In my second table called tests, this has 4 columns, one for subject_id, one for the subject_name, then one for a student with the higest score in a subject which is highestStudent_id. am trying to make highestStudent_id refer to student_id in my students table. This is the code i have below , am not sure if the syntax is correct:
CREATE TABLE students ( student_id SERIAL PRIMARY KEY,
player_name TEXT);
CREATE TABLE tests ( subject_id SERIAL,
subject_name,
highestStudent_id SERIAL REFERENCES students);
is the syntax highestStudent_id SERIAL REFERENCES students
correct? because i have seen another one like highestStudent_id REFERENCES students(student_id))
What would be the correct way of creating the foreign key in postgresql please?
serial
it should defined asinteger
.serial
is not a "real" data type, it's a short hand for populating the default value from sequence – a_horse_with_no_name