@stickybit is correct if you want to allow a movie to have multiple categories. And that is not unreasonable. But if that is not the case and you want to ensure a movie is in only 1 category, then your fk structure is reversed. It's the difference between a M:M relationship and a 1:M relationship.
create table categories(
category_id serial
, category character varying(50)
, constraint categories_pk primary key (category_id)
, constraint category_uk unique(category )
);
create table movies(
movie_id serial
, category_id int
, title character varying(50)
, release_dt date
, url character varying(100)
, _local character varying(50)
, resume character varying(200)
, constraint movies_pk primary key(movie_id)
, constraint movies_uk unique(title)
, constraint movies2category_fk
foreign key (category_id)
references categories(category_id)
);
A couple other just random notes:
- Don't use names "local" and/or "release". Although Postgres does not consider them key words the SQL standard does, at least according to Postgres Appendix C. Or any other listed values, they can become reserved in any future any time.
- Use character varying instead of char. Char is fixed length so for title char(50) always requires 50 characters, even for the movie "W". Although Postgres makes 'allowances' for trailing spaces, most of the time.
- You might want to get into the habit on naming constraints, espically if you work (will work) with other DBMS. Postgres does a pretty good job generating names, others not so much. You'll appreciate taking the extra time whin you have to solve an issue with a name constarint like SYS_C0010676.