New to relational DBMS here. I have created table Users and table Sports.
Users Table
CREATE TABLE IF NOT EXISTS schema1.users
(
user_id serial NOT NULL,
user_name text NOT NULL,
user_location text NOT NULL,
sport_id integer,
CONSTRAINT users_pkey PRIMARY KEY (user_id)
CONSTRAINT sports_pkey FOREIGN KEY (sport_id)
REFERENCES schema1.sports (sport_id) MATCH SIMPLE
ON UPDATE NO ACTION
ON DELETE NO ACTION
NOT VALID
);
Sports Table
CREATE TABLE IF NOT EXISTS schema1.sports
(
sport_id serial NOT NULL,
sport_name text,
sport_category text,
CONSTRAINT sports_pkey PRIMARY KEY (sport_id)
);
A person may be interested in more than one sports. For example, user A may be interested in basketball and baseball.
How this should be handled in order to be able to relate one user to multiple ids from the second table?