· 6 years ago · Mar 22, 2019, 07:34 PM
1use [master]
2
3IF NOT EXISTS (SELECT name FROM sys.databases WHERE name = N'BasketballStatistic')
4 CREATE DATABASE [BasketballStatistic]
5else
6 DROP DATABASE [BasketballStatistic]
7 CREATE DATABASE [BasketballStatistic]
8go
9use [BasketballStatistic]
10
11CREATE TABLE Team
12(
13team_id INT IDENTITY(1,1) NOT NULL,
14
15team_city VARCHAR(50) NOT NULL,
16team_name VARCHAR(50) NOT NULL,
17team_fondation_date DateTime Not null,
18PRIMARY KEY(team_id)
19);
20
21CREATE TABLE Players
22(
23player_id INT IDENTITY(1,1) NOT NULL,
24current_team_id int not Null,
25player_name VARCHAR(50) NOT NULL,
26player_surname VARCHAR(50) NOT NULL,
27player_country VARCHAR(50) NOT NULL,
28player_born_date DateTime Not null,
29PRIMARY KEY(player_id)
30);
31
32CREATE TABLE Contracts
33(
34Contract_id INT IDENTITY(1,1) NOT NULL,
35team_id int not Null,
36player_id int not Null,
37player_number int not Null,
38contract_start_time DateTime not null,
39contract_end_time DateTime not null,
40PRIMARY KEY(Contract_id)
41);
42/**/
43CREATE TABLE Player_statistic
44(
45statistic_id INT IDENTITY(1,1) NOT NULL,
46Contract_id int not Null,
47one_point int not Null,
48two_point int not Null,
49three_point int not Null,
50fols_commited int not null,
51block_shots int not null,
52wins int not null,
53loses int not null,
54draws int not null,
55loses_on_draw int not null,
56wins_on_draw int not null,
57
58PRIMARY KEY(statistic_id)
59);