Sorry if the title is a bit confusing, but I don't really know how to convey the question in a straightforward way.
This is a design problem. Let's say you have this really simple tables
create table people (
id_person serial primary key,
name text null
)
create table dogs (
id_pet serial primary key,
id_person int null,
name text null,
CONSTRAINT dogs_people_id_person_fk FOREIGN KEY (id_person) REFERENCES people (id_person)
)
insert into people (name)
values ('Jerry'), ('Jenny'), ('Alan')
insert into dogs (id_person, name)
values (1, 'Felix'), (2, 'Pippo'), (2, 'Lampino')
So you list the people and then all the dogs they have; they can have 0 or many.
My question is: how can I say that Alan doesn't have a dog? Well, I can make a query and find out that there is no dog listed in dogs
for Alan. But I want to keep track of this information!
Let's say for example these data are obtained by interviewing people in a classroom: I don't want to have any doubt if Alan doesn't have a dog or if I haven't interviewed him yet.
So in a database design standpoint what is the more correct way to make it?
Should I add a new column in people (like, has_no_dogs
)? But people
is about people, seems a little forced to add an information about dogs in the people
table, doesn't it?
Should I add a new table? Something like dogless_people
where I list the people I know that don't have a dog. Or is redundant?
What do you suggest?
--EDIT
To add a little for my specific case:
people
is a big table, central in a relational net, whereas dogs
is very specific table used for just one topic. So I think it would be a bit "dirty" to add a column like has_no_dogs
, or interviewed
, in the people
table.