Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use [master]
- IF NOT EXISTS (SELECT name FROM sys.databases WHERE name = N'BasketballStatistic')
- CREATE DATABASE [BasketballStatistic]
- else
- DROP DATABASE [BasketballStatistic]
- CREATE DATABASE [BasketballStatistic]
- go
- use [BasketballStatistic]
- CREATE TABLE Team
- (
- team_id INT IDENTITY(1,1) NOT NULL,
- team_country VARCHAR(50) NOT NULL,
- team_city VARCHAR(50) NOT NULL,
- team_name VARCHAR(50) NOT NULL,
- team_fondation_date DateTime Not null,
- team_main_stadion int not null,
- PRIMARY KEY(team_id)
- );/*+*/
- CREATE TABLE Team_Statistic
- (
- team_statistic_id INT IDENTITY(1,1) NOT NULL,
- team_id int not Null,
- wins int not null,
- loses int not null,
- loses_on_draw int not null,
- wins_on_draw int not null,
- PRIMARY KEY(Team_statistic_id)
- );/*+*/
- /*CREATE TABLE Team_Stadion
- (
- Team_Stadion_id INT IDENTITY(1,1) NOT NULL,
- team_id INT not null,
- Stadion_id INT NOT NULL,
- Start_stadion_use DateTime Not null,
- Finish_stadion_use DateTime Not null,
- PRIMARY KEY(Team_Stadion_id)
- );*/
- CREATE TABLE Stadion
- (
- Stadion_id INT IDENTITY(1,1) NOT NULL,
- Stadion_name VARCHAR(50) NOT NULL,
- Stadion_country VARCHAR(50) NOT NULL,
- Stadion_city VARCHAR(50) NOT NULL,
- Stadion_fondation_date DateTime Not null,
- Stadion_places_count int not null,
- Stadion_location_latitude float NOT NULL,
- Stadion_location_longitude fload NOT NULL,
- PRIMARY KEY(Stadion_id)
- );/*+*/
- CREATE TABLE Players
- (
- player_id INT IDENTITY(1,1) NOT NULL,
- current_team_id int not Null,
- player_name VARCHAR(50) NOT NULL,
- player_surname VARCHAR(50) NOT NULL,
- player_country VARCHAR(50) NOT NULL,
- player_born_date DateTime Not null,
- PRIMARY KEY(player_id)
- );/*+*/
- CREATE TABLE Player_Contracts
- (
- Contract_id INT IDENTITY(1,1) NOT NULL,
- team_id int not Null,
- player_id int not Null,
- player_amplua VARCHAR(50) NOT NULL,/*goalkeeper defender*/
- player_number_on_contract int not Null,
- contract_start_time DateTime not null,
- contract_deyure_end_time DateTime not null,
- contract_defacto_end_time DateTime,
- PRIMARY KEY(Contract_id)
- );
- /*+*/
- CREATE TABLE Player_statistic
- (
- statistic_id INT IDENTITY(1,1) NOT NULL,
- Contract_id int not Null,
- total_time_played time not null,
- goals_from_game_bullits_count int not null,
- goals_from_game_count int not Null,
- key_passes_for_goals_count int not Null,
- saves_count int not Null,
- two_min_fare int not Null,
- five_min_fare int not_Null,
- wins int not null,
- loses int not null,
- loses_on_draw int not null,
- wins_on_draw int not null,
- PRIMARY KEY(statistic_id)
- );/*+-*/
- CREATE TABLE Coach
- (
- coach_id INT IDENTITY(1,1) NOT NULL,
- current_team_id int not Null,
- coach_name VARCHAR(50) NOT NULL,
- coach_surname VARCHAR(50) NOT NULL,
- coach_country VARCHAR(50) NOT NULL,
- coach_city VARCHAR(50) NOT NULL,
- coach_born_date DateTime Not null,
- PRIMARY KEY(coach_id)
- );/*+*/
- CREATE TABLE Coach_Contracts
- (
- Contract_id INT IDENTITY(1,1) NOT NULL,
- team_id int not Null,
- coach_id int not Null,
- contract_start_time DateTime not null,
- contract_deyure_end_time DateTime not null,
- contract_defacto_end_time DateTime,
- PRIMARY KEY(Contract_id)
- );
- /*+*/
- CREATE TABLE Coach_statistic
- (
- statistic_id INT IDENTITY(1,1) NOT NULL,
- Contract_id int not Null,
- wins int not null,
- loses int not null,
- loses_on_draw int not null,
- wins_on_draw int not null,
- PRIMARY KEY(statistic_id)
- );/*+*/
- CREATE TABLE referies
- (
- referie_id INT IDENTITY(1,1) NOT NULL,
- referie_name VARCHAR(50) NOT NULL,
- referie_surname VARCHAR(50) NOT NULL,
- referie_born_date DateTime Not null,
- PRIMARY KEY(referie_id)
- );/*+*/
- /*common table for Tour and team*/
- CREATE TABLE Tournament
- (
- Tournament_id INT IDENTITY(1,1) NOT NULL,
- Tournament_name VARCHAR(50) NOT NULL,
- Tournament_status VARCHAR(50) NOT NULL,/*international local*/
- PRIMARY KEY(Tournament_id)
- );/*+*/
- CREATE TABLE Game
- (
- Game_id INT IDENTITY(1,1) NOT NULL,
- Tournament_id int NOT NULL,
- Stadion_id int not Null,
- referie_id int not null,
- home_team int not null,
- guest_team int not null,
- home_team_score int not null,
- guest_team_score int not null,
- start_time date not null,
- PRIMARY KEY(Game_id)
- );/*+*/
- CREATE TABLE GameApplication
- (
- GameApplication_id INT IDENTITY(1,1) NOT NULL,
- Game_id int NOT NULL,
- Player_id int not null,
- Team_id int not null,
- PRIMARY KEY(GameApplication_id)
- );/*+*/
- CREATE TABLE GameLog
- (
- GameLog_id INT IDENTITY(1,1) NOT NULL,
- Game_id int not null,
- action_time Time not null,
- main_game_period bit not null
- game_period int not null,
- player_id int not null,
- player_action int not null,/*action of player triger for statistic and score update*/
- PRIMARY KEY(GameLog_id)
- );
- CREATE TABLE PlayerAction
- (
- Player_Action_id INT IDENTITY(1,1) NOT NULL,
- action_commited VARCHAR(50) NOT NULL, /*goal, assist, save, boolit, noboolit*/
- PRIMARY KEY(Player_Action_id)
- );
- ALTER TABLE Team_statistic
- WITH CHECK ADD CONSTRAINT FK_Team_ID FOREIGN KEY(team_id)
- REFERENCES Team(team_id);
- ALTER TABLE Players
- WITH CHECK ADD CONSTRAINT FK_Current_Team_ID FOREIGN KEY(current_team_id)
- REFERENCES Team(team_id);
- ALTER TABLE Player_Contracts
- WITH CHECK ADD CONSTRAINT FK_Team_ID FOREIGN KEY(team_id)
- REFERENCES Team(team_id);
- ALTER TABLE Player_Contracts
- WITH CHECK ADD CONSTRAINT FK_Player_Id FOREIGN KEY(player_id )
- REFERENCES Players(player_id);
- ALTER TABLE Player_statistic
- WITH CHECK ADD CONSTRAINT FK_Contract_Id FOREIGN KEY(contract_id)
- REFERENCES Player_Contracts(contract_id );
- ALTER TABLE Coach
- WITH CHECK ADD CONSTRAINT FK_Current_team_id FOREIGN KEY(current_team_id)
- REFERENCES Team(team_id);
- ALTER TABLE Coach_Contracts
- WITH CHECK ADD CONSTRAINT FK_Team_id FOREIGN KEY(team_id)
- REFERENCES Team(team_id);
- ALTER TABLE Coach_Contracts
- WITH CHECK ADD CONSTRAINT FK_Coach_id FOREIGN KEY(coach_id)
- REFERENCES Coach(coach_id);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement