-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconnectfourdatabase.sql
69 lines (62 loc) · 2.24 KB
/
connectfourdatabase.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
create database connectfour;
use connectfour;
create table Game(
id integer not null auto_increment,
datePlayed datetime default current_timestamp,
nbrofcols int,
nbrofrows int,
nbrofplayers int,
constraint PK_ID primary key (id)
);
create table Credentials(
username varchar(60) not null,
password varchar(60) not null,
constraint PK_USERNAME primary key (username)
);
create table Player(
username varchar(60) not null,
name varchar(150),
playerid varchar(25) default 'Player',
constraint PK_USERNAME_PLAYER primary key (username),
constraint FK_USERNAME_PLAYER foreign key (username) references Credentials (username) on delete cascade
);
create table Gamestatus(
gameid integer not null,
finished boolean,
winner varchar(60) default null,
date datetime default current_timestamp,
constraint PK_GAMEID_GAMESTATUS primary key (gameid),
constraint FK_GAMEID_GAMESTATUS foreign key (gameid) references Game (id) on delete cascade,
constraint FK_WINNER_GAMESTATUS foreign key (winner) references Credentials (username) on delete set null
);
create table Playing(
playernbr int not null,
gameid integer not null,
color varchar(60),
username varchar(60),
isAI boolean,
aiDifficulty varchar(15),
constraint PK_PLAYING_PLAYERNBR primary key (playernbr, gameid),
constraint FK_PLAYING_PLAYERNBR foreign key (username) references Credentials (username) on delete cascade,
constraint FK_PLAYING_GAMEID foreign key (gameid) references Game (id) on delete cascade
);
create table Played(
username varchar(60) not null,
gameid integer not null,
constraint PK_PLAYED_USERRNAME primary key (username, gameid),
constraint FK_PLAYED_USERNAME foreign key (username) references Credentials (username) on delete cascade,
constraint FK_PLAYED_GAMEID foreign key (gameid) references Game (id) on delete cascade
);
create table Moves(
gameid integer not null,
movenbr integer not null,
player integer,
username varchar(60) default null,
rowCoord integer not null,
colCoord integer not null,
color varchar(15),
date datetime default current_timestamp,
constraint PK_MOVES_GAMEID_MOVENBR primary key (gameid, movenbr),
constraint FK_MOVES_GAMEID foreign key (gameid) references Game (id) on delete cascade,
constraint FK_MOVES_PLAYER foreign key (username) references Credentials (username) on delete set null
);