-
Notifications
You must be signed in to change notification settings - Fork 0
/
CarRace3DCreateSQL.txt
52 lines (44 loc) · 1.34 KB
/
CarRace3DCreateSQL.txt
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
drop database if exists CarRace;
create database CarRace;
use CarRace;
drop table if exists Gambler;
drop table if exists Race;
drop table if exists Gamble;
drop table if exists Car;
create table Car (
carId integer not null AUTO_INCREMENT,
type varchar(25),
size varchar(25),
shape varchar(25),
color varchar(25),
constraint pkCar primary key (carId)
);
ALTER TABLE Car AUTO_INCREMENT=1;
create table Gambler (
gamblerId integer not null AUTO_INCREMENT,
name varchar(25),
wallet float,
constraint pkGambler primary key (gamblerId)
);
ALTER TABLE Gambler AUTO_INCREMENT=100;
create table Race (
raceId integer not null AUTO_INCREMENT,
name varchar(25),
startTime date,
winner integer not null,
constraint pkRace primary key (raceId, startTime),
constraint fkWinner foreign key (winner) references Gambler(gamblerId)
);
ALTER TABLE Race AUTO_INCREMENT=10000;
create table Gamble (
gambleId integer not null AUTO_INCREMENT,
gamblerId integer,
raceId integer,
carId integer,
amount float,
constraint pkGamble primary key (GamblerId),
constraint fkGambler foreign key (GambleId) references Gambler(gamblerId),
constraint fkRace foreign key (raceId) references Race(raceId),
constraint fkCar foreign key (carId) references Car(carId)
);
ALTER TABLE Gamble AUTO_INCREMENT=1000;