06/01/15 19:51:17 .net
>>113
それなら>>111の設計の方がきれいだと思うぞ。
PostgreSQLならこういう技も使えるが。
create table user_master (
user_id number primary key
)
create table option_master (
option_id int primary key,
option_class int not null -- 1なら制限なし 2なら制限あり
)
create unique index option_master_class_idx on option_master (
option_id,
option_class
);
create table user_option (
user_id number not null,
option_id int not null,
foreign key ( user_id )
references user_master(user_id),
foreign key ( option_id )
references option_master( option_id ),
primary key ( user_id, option_id )
)
create table user_option_limit (
user_id number not null,
option_id int not null,
option_class int not null,
option_limit int not null,
primary key ( user_id, option_id ),
foreign key ( user_id )
references user_master( user_id ),
foreign key ( option_id, option_class )
references option_master( option_id, option_class ),
check ( option_class = 2 ),
check ( option_limit > 0 )
)
>>100の結果が欲しい場合はuser_optionとuser_option_limitを
outer joinするか、そういうviewを作っておく。