Quantcast
Viewing latest article 23
Browse Latest Browse All 31

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

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?


Viewing latest article 23
Browse Latest Browse All 31

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>