Currently, my database holds 7 interests (labelled I1 to I7 in
the Interests table). My dilemma is what happens if some one
chooses 8 interests (what happens to the one extra interest)
- do I lose it? Is there a better way to go about this?
There is a far better way to do this: you need a separate table
linking users and interests. (This is basic normalized rdbms design,
so you probably would benefit from any of the sql tutorials floating
around the web at devshed, webmonkey, and for all I know here too!)
So you would have:
create table users
(
user_id serial, -- or however your dbms defines an auto-number
public_id text, -- e.g. email address, who they currently sign in as
name text
-- other boring stuff such as address, salary...
);
create table interests
(
interest_id serial,
description text
);
create table user_interests
(
interest_id int4,
user_id int4
);
Now a user can have any number of interests, and you can also do other nice things like say
select users.name from users, user_interests, interests where users.user_id = user_interests.user_id and user_interests.interest_id = interests.interest_id and interests.description = 'php programming';
to get a list of names for everyone who is interested in php programming.