I mean things like:
FK1 -> 1FK2 -> 2PK
Please, note that 1FK2 is a PK to FK1, but the 1FK2 is a FK to 2PK. So the key in the nested structure is a FK and a PK.
An example:
--- Like an interface
CREATE TABLE q_content (
user_id SERIAL PRIMARY KEY, ---);
---- tables that refer to it
CREATE TABLE questions (
user_id SERIAL
references q_content(user_id) ---);
CREATE TABLE removed_questions (
user_id SERIAL
references questions(user_id) ---);
Yes, a column can be a primary key of its table as well as a foreign key to a parent table.
However, in this case you don’t need to use
SERIALas the data type forquestions.user_idandremoved_questions.user_id. TheSERIALdata type implicitly creates a new sequence object, and you don’t need that since these primary keys must contain only values that already exist in the table they reference.Also this is tangential to your question, but I wouldn’t define a
removed_questionstable at all. This should be an attribute column in thequestionstable.