2012-03-26 8 views
-1

この状況では、2つのクラスの間に1対多の関係があります。私は水泳競技をしており、競技には水泳選手がいることができます。SQL不明な属性の数

私はこのためにSQLテーブルを作成できますが、私はスイミング競技会で外国人キーとして主キーを使用する必要があることを知っていますが、それは不明なので正しい数の属性を表す方法はわかりません。

+1

なぜ属性の数は不明ですか? – keyser

+0

テーブルを作成する前に、アプリケーションの設計/アーキテクチャの面でもう少し時間を費やす必要があるようです。 –

+0

あなたの質問は特定ではありません。答えを得たい場合は、あなたの状況を具体的に説明する必要があります。この質問を閉じてください。 – Ben

答えて

1

これはm:n関係と呼ばれ、通常マッピングテーブルで解決されます。このような

何か:

create table swimmer 
(
    id   integer not null primary key, 
    lastname varchar(100) not null, 
    firstname varchar(100) 
) 

create table competition 
(
    id  integer not null primary key, 
    name  varchar(50) not null, 
    comp_date date not null 
) 

create table participant 
( 
    swimmer_id   integer not null, 
    competition_id  integer not null, 
    rank_in_competetion integer, 
    primary key (swimmer_id, competition_id), 
    constraint fk_participant_swimmer (swimmer_id) references swimmer(id), 
    constraint fk_participant_competition (competition_id) references competition(id) 
)  
関連する問題