Re: database design suggestion
Posted by: Peter Brawley
Date: April 02, 2015 10:39AM

If the requirement now is for 2 characteristics, it may be 3 or 29 next year, so this might be a start ...

users( uid int unsigned primary key auto_increment, name, ...)

characteristics( cid int unsigned primary key auto_increment, name, ...)

char_attrs(
caid int unsigned primary key auto_increment, name,
cid int unsigned,
name varchar(16),
description varchar(255),
foreign key(cid) references characteristics(cid) on update cascade on delete cascade
)

user_attrs(
uid int unsigned,
caid int unsigned,
primary key(uid,caid),
foreign key(uid) references users(uid) on update cascade on delete cascade,
foreign key(caid) references char_attrs(caid) on update cascade on delete cascade
)

... and to find the chars & attrs of user 7 ...

select u.name, c.name, ca.name
from user_attrs ua
join users u using(uid)
join char_attrs ca using(caid)
join characteristics c using(cid)
where u.uid=7
order by c.name,ca.name;

Then you write all the other queries that can be anticipated, adjusting the data strcturers as you go till every anticipated query question can be answered.

Options: ReplyQuote


Subject
Written By
Posted
Re: database design suggestion
April 02, 2015 10:39AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.