season SERIAL PRIMARY KEY,
name VARCHAR NOT NULL,
- UNIQUE ( season )
+ UNIQUE ( name )
);
CREATE TABLE tournaments (
location VARCHAR NOT NULL,
"date" DATE NOT NULL,
machine INTEGER NOT NULL REFERENCES machines,
- scoringsystem INTEGER NOT NULL REFERENCES scoringsystems
+ scoringsystem INTEGER NOT NULL REFERENCES scoringsystems,
+
+ UNIQUE ( season, name )
);
CREATE TABLE rounds (
round INTEGER NOT NULL,
parallel INTEGER NOT NULL,
player INTEGER NOT NULL REFERENCES players,
+ position INTEGER NOT NULL,
UNIQUE (tournament, round, player),
+ UNIQUE (tournament, round, parallel, position),
FOREIGN KEY (tournament, round, parallel) REFERENCES groups (tournament, round, parallel),
PRIMARY KEY (tournament, round, parallel, player)
);
round INTEGER NOT NULL,
parallel INTEGER NOT NULL,
player INTEGER NOT NULL REFERENCES players,
+ songnumber INTEGER NOT NULL,
song INTEGER NOT NULL REFERENCES songs,
playmode VARCHAR CHECK (playmode IS NULL OR playmode IN ('single','double')),
FOREIGN KEY (song) REFERENCES songs (song),
FOREIGN KEY (song, playmode, difficulty) REFERENCES songratings (song, playmode, difficulty),
FOREIGN KEY (tournament, round, parallel, player) REFERENCES roundparticipation (tournament, round, parallel, player),
+ UNIQUE (tournament, round, parallel, player, songnumber),
PRIMARY KEY (tournament, round, parallel, player, song)
);