Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 6.87 KB | None | 0 0
  1. use [master]
  2.  
  3. IF NOT EXISTS (SELECT name FROM sys.databases WHERE name = N'HockeyStatistic')
  4.     CREATE DATABASE [HockeyStatistic]
  5. else
  6.     DROP DATABASE [HockeyStatistic]
  7.     CREATE DATABASE [HockeyStatistic]
  8. go
  9. use [HockeyStatistic]
  10.  
  11. CREATE TABLE Team
  12. (
  13. team_id INT IDENTITY(1,1) NOT NULL,
  14. team_country VARCHAR(50) NOT NULL,
  15. team_city VARCHAR(50) NOT NULL,
  16. team_name VARCHAR(50) NOT NULL,
  17. team_fondation_date DateTime Not null,
  18. team_main_stadion int not null,
  19. PRIMARY KEY(team_id)
  20. );/*+*/
  21.  
  22. CREATE TABLE Team_Statistic
  23. (
  24. team_statistic_id INT IDENTITY(1,1) NOT NULL,
  25. team_id int not Null,
  26.  
  27. wins int not null,
  28. loses int not null,
  29. loses_on_draw int not null,
  30. wins_on_draw int not null,
  31.  
  32. PRIMARY KEY(team_statistic_id)
  33. );/*+*/
  34. /*CREATE TABLE Team_Stadion
  35. (
  36.     Team_Stadion_id INT IDENTITY(1,1) NOT NULL,
  37.     team_id INT not null,
  38.     Stadion_id INT NOT NULL,
  39.     Start_stadion_use DateTime Not null,
  40.     Finish_stadion_use DateTime Not null,
  41.     PRIMARY KEY(Team_Stadion_id)
  42. );*/
  43.  
  44.  
  45. CREATE TABLE Stadion
  46. (
  47. stadion_id INT IDENTITY(1,1) NOT NULL,
  48.  
  49. stadion_name VARCHAR(50) NOT NULL,
  50. stadion_country VARCHAR(50) NOT NULL,
  51. stadion_city VARCHAR(50) NOT NULL,
  52. stadion_fondation_date DateTime Not null,
  53. stadion_places_count int not null,
  54. stadion_location_latitude float NOT NULL,
  55. stadion_location_longitude fload NOT NULL,
  56.  
  57. PRIMARY KEY(stadion_id)
  58. );/*+*/
  59.  
  60. CREATE TABLE Players
  61. (
  62. player_id INT IDENTITY(1,1) NOT NULL,
  63. current_team_id int not Null,
  64. player_name VARCHAR(50) NOT NULL,
  65. player_surname VARCHAR(50) NOT NULL,
  66. player_country  VARCHAR(50) NOT NULL,
  67. player_born_date DateTime Not null,
  68. PRIMARY KEY(player_id)
  69. );/*+*/
  70.  
  71.  
  72. CREATE TABLE Player_Contracts
  73. (
  74. contract_id INT IDENTITY(1,1) NOT NULL,
  75. team_id int not Null,
  76. player_id int not Null,
  77. player_amplua VARCHAR(50) NOT NULL,/*goalkeeper defender*/
  78. player_number_on_contract int not Null,
  79. contract_start_time DateTime not null,
  80. contract_deyure_end_time DateTime not null,
  81. contract_defacto_end_time DateTime,
  82. PRIMARY KEY(contract_id)
  83. );
  84. /*+*/
  85. CREATE TABLE Player_statistic
  86. (
  87. statistic_id INT IDENTITY(1,1) NOT NULL,
  88. contract_id int not Null,
  89.  
  90. total_time_played time not null,
  91. goals_from_game_bullits_count int not null,
  92. goals_from_game_count int not Null,
  93. key_passes_for_goals_count int not Null,
  94. saves_count int not Null,
  95. two_min_fare int not Null,
  96. five_min_fare int not_Null,
  97.  
  98. wins int not null,
  99. loses int not null,
  100. loses_on_draw int not null,
  101. wins_on_draw int not null,
  102. PRIMARY KEY(statistic_id)
  103. );/*+-*/
  104.  
  105. CREATE TABLE Coach
  106. (
  107. coach_id INT IDENTITY(1,1) NOT NULL,
  108. current_team_id int not Null,
  109. coach_name VARCHAR(50) NOT NULL,
  110. coach_surname VARCHAR(50) NOT NULL,
  111. coach_country  VARCHAR(50) NOT NULL,
  112. coach_city VARCHAR(50) NOT NULL,
  113. coach_born_date DateTime Not null,
  114. PRIMARY KEY(coach_id)
  115. );/*+*/
  116.  
  117. CREATE TABLE Coach_Contracts
  118. (
  119. contract_id INT IDENTITY(1,1) NOT NULL,
  120. team_id int not Null,
  121. coach_id int not Null,
  122. contract_start_time DateTime not null,
  123. contract_deyure_end_time DateTime not null,
  124. contract_defacto_end_time DateTime,
  125. PRIMARY KEY(contract_id)
  126. );
  127. /*+*/
  128. CREATE TABLE Coach_statistic
  129. (
  130. statistic_id INT IDENTITY(1,1) NOT NULL,
  131. Contract_id int not Null,
  132.  
  133. wins int not null,
  134. loses int not null,
  135. loses_on_draw int not null,
  136. wins_on_draw int not null,
  137.  
  138. PRIMARY KEY(statistic_id)
  139. );/*+*/
  140.  
  141.  
  142. CREATE TABLE Referies
  143. (
  144.  referie_id INT IDENTITY(1,1) NOT NULL,
  145.  referie_name VARCHAR(50) NOT NULL,
  146.  referie_surname VARCHAR(50) NOT NULL,
  147.  referie_born_date DateTime Not null,
  148.  
  149.  
  150. PRIMARY KEY(referie_id)
  151. );/*+*/
  152.  
  153.  
  154. CREATE TABLE Team_Tournament
  155. (
  156. team_tournament_id INT IDENTITY(1,1) NOT NULL,
  157. tournament_id int not null,
  158. team_id int not null,
  159. PRIMARY KEY(team_tournament_id )
  160. );
  161. /*common table for Tour and team*/
  162.  
  163. CREATE TABLE Tournament
  164. (
  165. tournament_id INT IDENTITY(1,1) NOT NULL,
  166. tournament_name VARCHAR(50) NOT NULL,
  167. tournament_status  VARCHAR(50) NOT NULL,/*international local*/
  168. PRIMARY KEY(tournament_id)
  169. );/*+*/
  170.  
  171. CREATE TABLE Game
  172. (
  173. game_id INT IDENTITY(1,1) NOT NULL,
  174. tournament_id int NOT NULL,
  175. stadion_id int not Null,
  176. referie_id int not null,
  177. home_team int not null,
  178. guest_team int not null,
  179. home_team_score int not null,
  180. guest_team_score int not null,
  181. start_time date not null,
  182.  
  183. PRIMARY KEY(game_id)
  184. );/*+*/
  185.  
  186. CREATE TABLE GameApplication
  187. (
  188. gameApplication_id INT IDENTITY(1,1) NOT NULL,
  189. game_id int NOT NULL,
  190. player_id int not null,
  191. team_id int not null,
  192. PRIMARY KEY(gameApplication_id)
  193. );/*+*/
  194.  
  195.  
  196. CREATE TABLE GameLog
  197. (
  198. gameLog_id INT IDENTITY(1,1) NOT NULL,
  199. game_id int not null,
  200.  
  201. action_time Time not null,
  202. main_game_period bit not null
  203. game_period int not null,
  204. player_id int not null,
  205. player_action int not null,/*action of player triger for statistic and score update*/
  206. PRIMARY KEY(gameLog_id)
  207. );
  208.  
  209. CREATE TABLE PlayerAction
  210. (
  211.     player_Action_id INT IDENTITY(1,1) NOT NULL,
  212.     action_commited VARCHAR(50) NOT NULL, /*goal, assist, save, boolit, noboolit*/
  213.     PRIMARY KEY(player_Action_id)
  214. );
  215.  
  216.  
  217.  
  218. ALTER TABLE Team_statistic
  219. WITH CHECK ADD CONSTRAINT FK_Team_ID FOREIGN KEY(team_id)
  220. REFERENCES Team(team_id);
  221.  
  222. ALTER TABLE Players
  223. WITH CHECK ADD CONSTRAINT FK_Current_Team_ID FOREIGN KEY(current_team_id)
  224. REFERENCES Team(team_id);
  225.  
  226. ALTER TABLE Player_Contracts
  227. WITH CHECK ADD CONSTRAINT FK_Team_ID FOREIGN KEY(team_id)
  228. REFERENCES Team(team_id);
  229.  
  230. ALTER TABLE Player_Contracts
  231. WITH CHECK ADD CONSTRAINT FK_Player_Id FOREIGN KEY(player_id )
  232. REFERENCES Players(player_id);
  233.  
  234. ALTER TABLE Player_statistic
  235. WITH CHECK ADD CONSTRAINT FK_Contract_Id FOREIGN KEY(contract_id)
  236. REFERENCES Player_Contracts(contract_id );
  237.  
  238. ALTER TABLE Coach
  239. WITH CHECK ADD CONSTRAINT FK_Current_team_id FOREIGN KEY(current_team_id)
  240. REFERENCES Team(team_id);
  241.  
  242. ALTER TABLE Coach_Contracts
  243. WITH CHECK ADD CONSTRAINT FK_Team_id FOREIGN KEY(team_id)
  244. REFERENCES Team(team_id);
  245.  
  246. ALTER TABLE Coach_Contracts
  247. WITH CHECK ADD CONSTRAINT FK_Coach_id FOREIGN KEY(coach_id)
  248. REFERENCES Coach(coach_id);
  249.  
  250. ALTER TABLE Coach_statistic
  251. WITH CHECK ADD CONSTRAINT FK_Contract_id FOREIGN KEY(сontract_id)
  252. REFERENCES Coach_Contracts(сontract_id);
  253.  
  254. ALTER TABLE Team_Tournament
  255. WITH CHECK ADD CONSTRAINT FK_Tournament_id FOREIGN KEY(tournament_id)
  256. REFERENCES Tournament(tournament_id);
  257.  
  258. ALTER TABLE Team_Tournament
  259. WITH CHECK ADD CONSTRAINT FK_Team_id FOREIGN KEY(team_id)
  260. REFERENCES Team(team_id);
  261.  
  262. ALTER TABLE Game
  263. WITH CHECK ADD CONSTRAINT FK_Tournament_id FOREIGN KEY(tournament_id)
  264. REFERENCES Tournament(tournament_id);
  265.  
  266. ALTER TABLE Game
  267. WITH CHECK ADD CONSTRAINT FK_Stadion_id FOREIGN KEY(stadion_id)
  268. REFERENCES Stadion(stadion_id;
  269.  
  270. ALTER TABLE Game
  271. WITH CHECK ADD CONSTRAINT FK_Referie_id FOREIGN KEY(referie_id)
  272. REFERENCES Referies(referie_id);
  273.  
  274. ALTER TABLE GameApplication
  275. WITH CHECK ADD CONSTRAINT FK_Game_id FOREIGN KEY(game_id)
  276. REFERENCES Referies(referie_id);
  277.  
  278. ALTER TABLE GameLog
  279. WITH CHECK ADD CONSTRAINT FK_Game_id FOREIGN KEY(game_id)
  280. REFERENCES  Game(game_id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement