頼むから正規化しろよ 第二正規形at DB
頼むから正規化しろよ 第二正規形 - 暇つぶし2ch114:NAME IS NULL
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を作っておく。



次ページ
続きを表示
1を表示
最新レス表示
レスジャンプ
類似スレ一覧
スレッドの検索
話題のニュース
おまかせリスト
オプション
しおりを挟む
スレッドに書込
スレッドの一覧
暇つぶし2ch