Parts Implemented by Nurullah Topaloğlu

TABLES

This part explains how Players, Coaches and Referees tables are structured and what operations can run on them.

Players Table

  • Attributes of the Players Table.
Name Type Primary Key Foreign Key Auto Increment
id SERIAL 1 0 1
name TEXT 0 0 0
surname TEXT 0 0 0
age INT 0 0 0
nation INT 0 1 0
team TEXT 0 0 0
field TEXT 0 0 0
goal INT 0 0 0
  • name holds the name of the player.
  • surname holds the surname of the player.
  • age holds the age of the player.
  • nation holds the id of the players nation referenced from the country table.
  • team holds the team that player plays.
  • field* holds the players field in tthe pool.
  • goal holds number of goals that player has scored.

SQL Statement that initializes the Players Table:

DROP TABLE IF EXISTS PLAYERS;
CREATE TABLE PLAYERS(
ID SERIAL PRIMARY KEY,
NAME TEXT,
SURNAME TEXT,
AGE INT,
NATION INT,
TEAM TEXT,
FIELD TEXT,
GOAL INT);

ALTER TABLE PLAYERS ADD CONSTRAINT FK_PLAYERS_COUNTRIES FOREIGN KEY (NATION)
REFERENCES COUNTRIES (ID) ON DELETE SET NULL ON UPDATE CASCADE;

Since Players(Nation) is referenced from Countries(id) and it is ON DELETE SET NULL ON UPDATE CASCADE, whenever a country is deleted, it will be NULL

Coaches Table

  • Attributes of the Coaches Table.
Name Type Primary Key Foreign Key Auto Increment
id SERIAL 1 0 1
name TEXT 0 0 0
surname TEXT 0 0 0
nation INT 0 1 0
team TEXT 0 0 0
  • name holds the name of the coach.
  • surname holds the surname of the coach.
  • nation holds the id of the coachs nation referenced from the country table.
  • team holds the team that coach manages.

SQL Statement that initializes the Coaches Table:

DROP TABLE IF EXISTS COACHES;
CREATE TABLE COACHES(
ID SERIAL PRIMARY KEY,
NAME TEXT,
SURNAME TEXT,
NATION INT,
TEAM TEXT);

ALTER TABLE COACHES ADD CONSTRAINT FK_COACHES_COUNTRIES FOREIGN KEY (NATION)
REFERENCES COUNTRIES (ID) ON DELETE SET NULL ON UPDATE CASCADE;

Since Coaches(Nation) is referenced from Countries(Id) and it is ON DELETE SET NULL ON UPDATE CASCADE, whenever a country is deleted, it will be NULL

Referees Table

  • Attributes of the Referees Table.
Name Type Primary Key Foreign Key Auto Increment
id SERIAL 1 0 1
name TEXT 0 0 0
surname TEXT 0 0 0
league INT 0 1 0
city TEXT 0 0 0
  • name holds the name of the referee.
  • surname holds the surname of the referee.
  • league describes the level of the referees as int referenced from the league table.
  • city holds the city that referee is in.

SQL Statement that initializes the Referees Table:

DROP TABLE IF EXISTS REFEREES;
CREATE TABLE REFEREES(
ID SERIAL PRIMARY KEY,
NAME TEXT,
SURNAME TEXT,
LEAGUE INT,
CITY TEXT);

ALTER TABLE REFEREES ADD CONSTRAINT FK_REFEREES_LEAGUES FOREIGN KEY (LEAGUE)
REFERENCES LEAGUES   (ID) ON DELETE SET NULL ON UPDATE CASCADE;

Since Referees(League) is referenced from Leagues(Id) and it is ON DELETE SET NULL ON UPDATE CASCADE, whenever a league is deleted, it will be NULL