Sample Header Ad - 728x90

What problems are there in not using a primary key column at all?

1 vote
1 answer
6712 views
What purpose would a primary key column serve on a table such as post_versions here? Nothing refers to it, and there are no queries where I will ever want to select a row by post_versions.id. It'll be joined to posts in most queries. CREATE TABLE posts ( id SERIAL PRIMARY KEY, created TIMESTAMPTZ NOT NULL DEFAULT now(), user_id INTEGER NOT NULL REFERENCES users ON DELETE RESTRICT ); CREATE TABLE post_versions ( id SERIAL PRIMARY KEY, -- serves no purpose, could remove I think post_id INTEGER NOT NULL REFERENCES posts ON DELETE CASCADE, updated TIMESTAMPTZ NOT NULL DEFAULT now(), body TEXT NOT NULL ); Are there any problems if I just remove it?
Asked by davidtgq (759 rep)
Mar 4, 2019, 02:06 PM
Last activity: Mar 4, 2019, 04:36 PM