View
30
Download
1
Category
Preview:
Citation preview
Myanmar Computer Co., Ltd.
Course: COMP 1639
B.Sc. Top up Programme
Date: December 2016
A dissertation submitted in partial fulfilment of the requirements for the University of Greenwich’s Bachelor of Science Degree in Business Information Technology.
COMP1639
Word Count: 4122
Prepared by: AUNG PYAE
Student ID: 000958762
COMP1639 DATABASE ENGINEERING
2
COURSE : BSC (HONS) BUSINESS IT
MODULE TITLE : DATABASE ENGINEERING
ASSIGNMENT TITLE : SPORT INFORMATION SYSTEM (FOOTBALL)
EXAM CYCLE : DECEMBER 2016
CANDIDATE NAME : AUNG PYAE
CANDIDATE NO : 000958762
SUMMITED DATE : 21-11-2016
MARKAR’S COMMENT :
MODERATOR’S COMMENT :
MARKS: MODERATED MARKS: FINAL MARKS:
COMP1639 DATABASE ENGINEERING
3
STATEMENT AND CONFIRMATION OF OWN WORK
All GREENWICH Education assessed assignments submitted by students must have this statement
as the cover page or it will not be accepted for marking. Please ensure that this statement is either
firmly attached to the cover of the assignment or electronically inserted into the front of the
assignment.
STUDENT DECLARATION
I have read and understood GREENWICH Education’s Policy on Academic Dishonesty and
Plagiarism.
I am confirmed the following details:
STUDENT ID/REGISTRATION NUMBER: 000958762
NAME : AUNG PYAE
CENTRE NAME : MCC TRAINING INSTITUTE (YATANARPON)
MODULE NAME : DATABASE ENGINEERING
MODULE LEADER : DAW THE SEINT AYE, DAW NEW NWE WIN
TITILE OF WORK : SPORT INFORMATION SYSTEM (FOOTBALL)
NUMBER OF WORDS : 4122
I confirm that this is my own work and that I have not plagiarized any part of it. I have also noted
the assessment criteria and pass mark for assignments.
DUE DATE : 21-11-2016
STUDENT SIGNATURE : AUNGPYAE
SUBBMITTED DATE : 21-11-2016
COMP1639 DATABASE ENGINEERING
4
CONTENTS CONTENTS ........................................................................................................................... 4
ACKNOWLEDGEMENT ........................................................................................................ 5
DATABASE DESIGN ............................................................................................................. 6
Assumptions about the database system and design .................................................................. 6
Enhanced Entity Relationship Diagram ................................................................................... 8
Relational schema for all entities.......................................................................................... 12
Normalization.................................................................................................................... 13
DATABASE SETUP ............................................................................................................. 20
Create commands of database and tables ............................................................................... 20
Population of database with data and values .......................................................................... 32
View, Trigger and Index ..................................................................................................... 35
SQL QUERIES ..................................................................................................................... 40
10 SQL queries that demonstrate for usefulness of database .................................................... 40
Future development report .................................................................................................. 50
Self-Assessment Sheet ........................................................................................................ 51
REFERENCES ..................................................................................................................... 52
COMP1639 DATABASE ENGINEERING
5
ACKNOWLEDGEMENT Knowledge is the most valuable prize of the world and the teachers who gives me knowledge are
valuable, thankful and grand persons. When I first arrived in MCC Institute, every learning courses
and texts are difficult for me but my teachers are very kind and help, teach and train me to the right
way with practical and technological skills to become the successful IT researcher student. So I great
thanks to my teachers with best wishes.
On designing and developing of this database management, I planned how to document the report
completely and help for teachers, professionals and researchers. I great thank to all teacher in our B.Sc.
programme for giving me great advices and logical thinking. I also thanks to our class tutor, Daw K
Zin Thant and mindful assistant lecturer, Daw Zin Thandar, give me strengths for my mind and teach
me to become well certified student.
Next I thanks to my friends who help me in solving the difficulties on finding the problems and
solutions of business cases. Finally, I great thank to MCC, NCC education, University of Greenwich
and all our education partners since they service me to get more ways for living and guide to become
a professional IT technician.
Aung Pyae
COMP1639 DATABASE ENGINEERING
6
DATABASE DESIGN
Assumptions about the database system and design I designed the relational database system for football management system and created with SQL
command queries (Data Query Language, Data Manipulation Language, Data Definition Language,
data Control Language) to use and manage the database.
There are 14 tables in football management database and all tables are connected with their
constraints. The judge team table recorded the judge team data to manage in match. The manager
table is used to record the managers with their profile information such as name, NRC, email, phone,
etc. The match table used to insert the matches with the related events. The match event table
recorded the events of whole match with their start date, end date and venues. Match player position
table is used to place for players to play which player plays in what position such as Goalkeeper,
Midfielder, Centre Forward. On match table is used to record goal records in match. Owner table and
Player table are uses to record information of owners and players as in the manager table. Player goal
table records the goals of players and position table has the values of football playing positions.
Round table record the match and teams with their playing positions. Team table records the
information of all teams with manger id, owner id and team score tables has the scores on each team.
Transfer table is used to record while transferring the player on match.
To start the match, there need to create and event in event table with other information. And match
table is needed to insert the match information with judge team and event. After inserting in match
table, two participating teams are need to record to round table by selecting LEFT or RIGHT positions.
Two rows need to insert and trigger will run for player placing in match player position table for each
row.
If a player wins a goals on playing the match, there will insert one row in on match table and if one
row is inserted, the trigger will run to insert on player goal and team score for goaled team and player.
All team score can be view from final result VIEW.
The whole database system uses MySQL relational database management system (RDBMS), which is
the most commercial database type in Structured Query Language (SQL).
COMP1639 DATABASE ENGINEERING
7
RDBMS is the best and common choice for storage of information in database with related primary
and foreign relations. So the football management database system uses RDBMS to keep record and
retrieve information.
SINCE ALL SQL KEYWORDS ARE FIXED AND ALL OTHER STUDENTS USE SAME
COMMAND LINES, I CANNOT AVOID PLAGARISM CHECKING WHICH HAS BEEN
COUNTED FOR THOSE KEYWORDS.
COMP1639 DATABASE ENGINEERING
8
Enhanced Entity Relationship Diagram
ap_manager
manager_nationali
ty
manager_address
manager_email
manager_name
manager_salary
ap_owner
owner_name owner_idowner_nrc
owner_phone
owner_personal_blo
g
ap_team
manage
ap_player_goal
ap_position
ap_player ap_match_player_position
manager_id
manager_phone
manager_nrc
manager_birthday
owns
owner_address
owner_email
owner_nationali ty
owner_birthday
goal participate
place
place
has
position_id
position_type
player_id
match_id
player_goal
team_id player_reg_date
player_id player_salary
player_name
player_nationality
player_birthday
player_number
player_nrc
player_email
player_phone player_w
eight_kg
player_height_ft
player_blood
ap_transfer
transfer
substitute
participate
dap_round
place for
ap_match
transfer place
divide
plays
plays
has
ap_on_match
ap_team_score
goal
get from
play
ap_match_event ap_judge_teamschedule control
match_id
player_id
trans fer_type
manager_blog
team_headquarter
team_name
team_country
manager_id
owner_id team_email
team_est_year
team_id
match_id
player_id
team_id
position_id
team_id
match_id
position
match_id on_match_goal
on_match_time team_id
team_score
team_id
match_id
event_id
match_date
judge_team_id
match_id
event_naneevent_id
event_start_date
event_end_date
event_venue
judge_team_contac
t
judge_team_id
judge_team_name
judge_team_memb
ers
Enhanced Entity Relationship Diagram for football management database system showing all entities,
attributes, relationships and multi sub classes connected with related notation signs using Chen’s
Database Notation method.
COMP1639 DATABASE ENGINEERING
9
Regular entity
ap_player
team_id player_reg_date
player_id player_salary
player_name
player_nationality
player_birthday
player_number
player_nrc
player_email
player_phone player_w
eight_kg
player_height_ft
player_blood
Player entity with attributes
ap_team
team_headquarter
team_name
team_country
manager_id
owner_id team_email
team_est_year
team_id
Team entity with attributes
There are 14 entities in the database and each linked with their related relationships.
COMP1639 DATABASE ENGINEERING
10
One to one entity
ap_manager
manager_nationali
ty
manager_address
manager_email
manager_name
manager_salary
ap_team
manage
manager_id
manager_phone
manager_nrc
manager_birthday
manager_blog
team_headquarter
team_name
team_country
manager_id
owner_id team_email
team_est_year
team_id
One to one entity relationship between manager and team. The relationship shows that one manager
manages only one team and one team only be controlled by one manager.
Relational schema for one to one entity
Manager_id
Manager_name
Manager_nrc
Manager_email
Manager_phone
Manager_birthday
Manager_national
ity
Manager_address
Manager_salary
Manager_blog
Team_id Owner_id
Manager_id*
Team_name
Team_email
Team_Est_year
Team_headquarte
rTeam_
ap_manager
ap_team
COMP1639 DATABASE ENGINEERING
11
Multi sub class entity
ap_match_player_position
ap_transfer
substitute
participate
dap_round
place for
match_id
player_id
transfer_type
match_id
player_id
team_id
position_id
team_id
match_id
position
This multi sub class entity shows the relationship of round and players. If selecting for match,
participate payers are inserted in match player position for player placing and substitute are used for
player transfer on match.
Mapping result for multi sub class entity
Match_id* Team_id Player_id Position_id
Match_id* Player_id Transfer_type
Match_id* Team_id position
ap_match_player_position
ap_transfer
ap_round
COMP1639 DATABASE ENGINEERING
12
Relational schema for all entities
Owner_id
Owner_name
Owner_nrc
Ower_email
Owner_phone
Owner_birthday
Owner_nationality
Owner_adddress
Owner_Personal_
blog
Manager_id
Manager_name
Manager_nrc
Manager_email
Manager_phone
Manager_birthday
Manager_national
ity
Manager_address
Manager_salary
Manager_blog
Judge_team_id name Total_me
mbers contact
Position_id
Position_type
Event_id Event_name
Event_Start_date
Event_End_date
Event_venue
Match_id Event_id Judge_team_id
Match_date
Match_id Team_id Player_id Position_id
Player_id Match_id Player_goal
Team_id Match_id Team_score
Team_id Owner_id
Manager_id
Team_name
Team_email
Team_Est_year
Team_headquarte
rTeam_
Match_id Player_id Transfer_type
Match_id Team_id On_match_goal
On_match_time
Match_id Team_id position
Player_id Team_id Player_name
Player_number
Player_nrc
Player_email
Player_phone
Player_Height_ft
Player_Weight_k
g
Player_birthday
Player_nationality
Player_salary
Player_Reg_date
Player_blood
ap_match_player_position
ap_on_match
ap_judge_team
ap_player_goal
ap_position
ap_transfer
ap_team_score
ap_round
ap_player
ap_team
ap_manager
ap_owner
ap_match_event
ap_match
Relational schema diagram clearly showing all tables in database with all relations
COMP1639 DATABASE ENGINEERING
13
Normalization (1): Judge team table
Judge_team_id Judge_team_name Judge_team_members Judge_contact
In this judge team table, there are no multivalued attributes and the values of each attribute (column)
such as (JUDGE_TEAM_ID, JUDGE_TEAM_NAME, etc.) are atomic. Therefore, the table is in 1st
Normal form.
This table is in 1NF and the value of each non-key attribute such as (JUDGE_TEAM_NAME,
JUDGE_TEAM_MEMBERS, etc.) is fully functionally dependent on the primary key
(JUDGE_TEAM_ID) in the table. Therefore, it’s in 2nd Normal Form.
This table is in 2NF and there are no functional dependencies between non-keys attribute in the judge
table and the JUDGE_TEAM_ID is primary key and other attributes are non-key attributes. Therefore,
it’s in 3rd Normal Form.
(2): Manager table
Mana
ger_i
d
Manag
er_nam
e
Mana
ger_nr
c
Manag
er_ema
il
Manage
r_phon
e
Manager
_birthda
y
Manager_
nationalit
y
Manage
r_addres
s
Manage
r_salary
Manag
er_blo
g
In this manager table, there are no multivalued attributes and the values of each attribute (column)
such as (MANAGER_ID, MANAGER_NAME, MANAGER_NRC, etc.) are atomic. Therefore, the
table is in 1st Normal form.
This table is in 1NF and the value of each non-key attribute such as (MANAGER_NAME,
MANAGER_NRC, etc.) is fully functionally dependent on the primary key (MANAER_ID) in the
table. Therefore, it’s in 2nd Normal Form.
This table is in 2NF and there are no functional dependencies between non-keys attribute in the table
and the MANAGER_ID is primary key and other attributes are non-key attributes. Therefore, it’s in
3rd Normal Form.
(3): Match table
COMP1639 DATABASE ENGINEERING
14
Match_id Event_id Judge_team_id Match_date
In this match table, there are no multivalued attributes and the values of each attribute (column) such
as (MATCH_ID, EVENT_ID, JUDGE_TEAM_ID, etc.) are atomic. Therefore, the table is in 1st
Normal form.
This table is in 1NF and the value of each non-key attribute such as (EVENT_ID, MATCH_DATE,
etc.) is fully functionally dependent on the primary key (MATCH_ID) in the table. Therefore, it’s in
2nd Normal Form.
This table is in 2NF and there are no functional dependencies between non-keys attribute in the table
and the MATCH_ID is primary key and other attributes are non-key attributes. Therefore, it’s in 3rd
Normal Form.
(4): Match event table
Event_id Event_name Event_start_date Event_end_date Event_venue
In this match event table, there are no multivalued attributes and the values of each attribute (column)
such as (EVENT_ID, EVENT_NAME, etc.) are atomic. Therefore, the table is in 1st Normal form.
This table is in 1NF and the value of each non-key attribute such as (EVENT_NAME,
EVETN_START_DATE, EVENT_END_DATE, etc.) is fully functionally dependent on the primary
key (EVENT_ID) in the table. Therefore, it’s in 2nd Normal Form.
This table is in 2NF and there are no functional dependencies between non-keys attribute in the table
and the EVENT_ID is primary key and other attributes are non-key attributes. Therefore, it’s in 3rd
Normal Form.
(5): Match player position table
Match_id Team_id Player_id Position_id
In this match player position table, there are no multivalued attributes and the values of each attribute
(column) such as (MATCH_ID, TEAM_ID, PLAYER_ID, POSITION_ID) are atomic. Therefore, the
table is in 1st Normal form.
COMP1639 DATABASE ENGINEERING
15
This table is in 1NF and the value of each non-key attribute such as (TEAM_ID, PLAYER_ID,
POSITION_ID) is fully functionally dependent on the primary key (MATCH_ID) in the table.
Therefore, it’s in 2nd Normal Form.
This table is in 2NF and there are no functional dependencies between non-keys attribute in the table
and the MATCH_ID is primary key and other attributes are non-key attributes. Therefore, it’s in 3rd
Normal Form.
(6): On match table
Match_id Team_id On_match_goal On_match_time
In this on match table, there are no multivalued attributes and the values of each attribute (column)
such as (MATCH_ID, TEAM_ID) are atomic. Therefore, the table is in 1st Normal form.
This table is in 1NF and the value of each non-key attribute such as (TEAM_ID,
ON_MATCH_GOAL, ON_MATCH_TIME) is fully functionally dependent on the primary key
(MATCH_ID) in the table. Therefore, it’s in 2nd Normal Form.
This table is in 2NF and there are no functional dependencies between non-keys attribute in the table
and the MATCH_ID is primary key and other attributes are non-key attributes. Therefore, it’s in 3rd
Normal Form.
(7): Owner table
Owne
r_id
Owner_
name
Owner
_nrc
Owner_
Owner_
phone
Owner_bi
rthday
Owner_nat
ionality
Owner_a
ddress
Owner_perso
nal_blog
In this owner table, there are no multivalued attributes and the values of each attribute (column) such
as (OWNER_ID, OWNER_NAME, etc.) are atomic. Therefore, the table is in 1st Normal form.
This table is in 1NF and the value of each non-key attribute such as (OWNER_NAME,
OWNER_NRC, OWNER_EMAIL, etc.) is fully functionally dependent on the primary key
(OWNER_ID) in the table. Therefore, it’s in 2nd Normal Form.
COMP1639 DATABASE ENGINEERING
16
This table is in 2NF and there are no functional dependencies between non-keys attribute in the table
and the OWNER_ID is primary key and other attributes are non-key attributes. Therefore, it’s in 3rd
Normal Form.
(8): Player table
Pla
yer
_id
Te
am
_i
d
Play
er_n
ame
Play
er_n
umb
er
Pla
yer
_nr
c
Play
er_e
Play
er
Play
er_p
hone
Play
er_b
lood
Playe
r_hei
ght_ft
Player
_weig
ht_kg
Playe
r_birt
hday
Player
_natio
nality
Play
er_s
alar
y
Playe
r_reg
_date
In this player table, there are no multivalued attributes and the values of each attribute (column) such
as (PLAYER_ID, PLAYER_NAME, etc.) are atomic. Therefore, the table is in 1st Normal form.
This table is in 1NF and the value of each non-key attribute such as (PLAYER_NAME,
PLAYER_NUMBER, etc.) is fully functionally dependent on the primary key (PLAYER_ID) in the
table. Therefore, it’s in 2nd Normal Form.
This table is in 2NF and there are no functional dependencies between non-keys attribute in the table
and the PLAYER_ID is primary key and other attributes are non-key attributes. Therefore, it’s in 3rd
Normal Form.
(9): Player goal table
Player_id Match_id Player_goal
In this player goal table, there are no multivalued attributes and the values of each attribute (column)
such as (PLAYER_ID, MATCH_ID, PLAYER_GOAL) are atomic. Therefore, the table is in 1st
Normal form.
This table is in 1NF and the value of each non-key attribute such as (MATCH_ID, LAYER_GOAL)
is fully functionally dependent on the primary key (PLAYER_ID) in the table. Therefore, it’s in 2nd
Normal Form.
COMP1639 DATABASE ENGINEERING
17
This table is in 2NF and there are no functional dependencies between non-keys attribute in the table
and the PLAYER_ID is primary key and other attributes are non-key attributes. Therefore, it’s in 3rd
Normal Form.
(10): Position table
Position_id Position_type
In this position table, there are no multivalued attributes and the values of each attribute (column)
such as (POSITION_ID, POSITION_TYPE) are atomic. Therefore, the table is in 1st Normal form.
This table is in 1NF and the value of each non-key attribute such as (POSITION_TYPE) is fully
functionally dependent on the primary key (POSITION _ID) in the table. Therefore, it’s in 2nd Normal
Form.
This table is in 2NF and there are no functional dependencies between non-keys attribute in the table
and the POSITION _ID is primary key and other attributes are non-key attributes. Therefore, it’s in 3rd
Normal Form.
(11): Round table
Match_id Team_id position
In this round table, there are no multivalued attributes and the values of each attribute (column) such
as (MATCH_ID, TEAM_ID, POSITION) are atomic. Therefore, the table is in 1st Normal form.
This table is in 1NF and the value of each non-key attribute such as (TEAM_ID, POSITION) is fully
functionally dependent on the primary key (MATCH _ID) in the table. Therefore, it’s in 2nd Normal
Form.
This table is in 2NF and there are no functional dependencies between non-keys attribute in the table
and the MATCH _ID is primary key and other attributes are non-key attributes. Therefore, it’s in 3rd
Normal Form.
(12): Team table
COMP1639 DATABASE ENGINEERING
18
Team_
id
Owner_
id
Manager
_id
Team_na
me
Team_em
ail
Team_est_y
ear
Team_headqua
rter
Team_coun
try
In this team table, there are no multivalued attributes and the values of each attribute (column) such as
(TEAM_ID, OWNER_ID, MANAGER_ID, etc) are atomic. Therefore, the table is in 1st Normal form.
This table is in 1NF and the value of each non-key attribute such as (OWNER_ID, MANAGR_ID,
TEAM_NAME, TEAM_EMAIL, etc.) is fully functionally dependent on the primary key (TEAM
_ID) in the table. Therefore, it’s in 2nd Normal Form.
This table is in 2NF and there are no functional dependencies between non-keys attribute in the table
and the TEAM _ID is primary key and other attributes are non-key attributes. Therefore, it’s in 3rd
Normal Form.
(13): Team score table
Team_id Match_id Team_score
In this team score table, there are no multivalued attributes and the values of each attribute (column)
such as (TEAM_ID, MATCH_ID, TEAM_SCORE) are atomic. Therefore, the table is in 1st Normal
form.
This table is in 1NF and the value of each non-key attribute such as (MATCH_ID, TEAM_SCORE) is
fully functionally dependent on the primary key (TEAM _ID) in the table. Therefore, it’s in 2nd
Normal Form.
This table is in 2NF and there are no functional dependencies between non-keys attribute in the table
and the TEAM _ID is primary key and other attributes are non-key attributes. Therefore, it’s in 3rd
Normal Form.
(14): Transfer table
Match_id Player_id Transfer_type
COMP1639 DATABASE ENGINEERING
19
In this transfer table, there are no multivalued attributes and the values of each attribute (column) such
as (MATCH_ID, PLAYER_ID, TRANSFER_TYPE) are atomic. Therefore, the table is in 1st Normal
form.
This table is in 1NF and the value of each non-key attribute such as (PLAYER_ID,
TRANSFER_TYPE) is fully functionally dependent on the primary key (MATCH _ID) in the table.
Therefore, it’s in 2nd Normal Form.
This table is in 2NF and there are no functional dependencies between non-keys attribute in the table
and the MATCH _ID is primary key and other attributes are non-key attributes. Therefore, it’s in 3rd
Normal Form.
COMP1639 DATABASE ENGINEERING
20
DATABASE SETUP
Create commands of database and tables (1): Create database
(2): Create query for judge team table
Result
(3): Create query for manager table
CREATE `aung_pyae_dbe_football`;
USE `aung_pyae_dbe_football`;
CREATE TABLE `ap_judge_team` (
`judge_team_id` varchar(50) NOT NULL,
`judge_team_name` varchar(50) NOT NULL,
`judge_team_members` int(11) NOT NULL,
`judge_contact` varchar(50) NOT NULL,
PRIMARY KEY (`judge_team_id`)
);
COMP1639 DATABASE ENGINEERING
21
Result
CREATE TABLE `ap_manager` (
`manager_id` varchar(50) NOT NULL,
`manager_name` varchar(50) NOT NULL,
`manager_nrc` varchar(50) NOT NULL,
`manager_email` varchar(50) NOT NULL,
`manager_phone` int(11) NOT NULL,
`manager_birthday` date NOT NULL,
`manager_nationality` varchar(50) NOT NULL,
`manager_address` text NOT NULL,
`manager_salary` double NOT NULL,
`manager_blog` varchar(50) NOT NULL,
PRIMARY KEY (`manager_id`)
);
COMP1639 DATABASE ENGINEERING
22
(4): Create query for match table
Result
(5): Create query for match event table
Result
CREATE TABLE `ap_match` (
`match_id` varchar(50) NOT NULL,
`event_id` varchar(50) NOT NULL,
`judge_team_id` varchar(50) NOT NULL,
`match_date` date NOT NULL,
PRIMARY KEY (`match_id`),
KEY `event_id` (`event_id`),
KEY `judge_team_id` (`judge_team_id`),
CONSTRAINT `ap_match_ibfk_1` FOREIGN KEY (`event_id`) REFERENCES `ap_match_event` (`event_id`),
CONSTRAINT `ap_match_ibfk_3` FOREIGN KEY (`judge_team_id`) REFERENCES `ap_judge_team` (`judge_team_id`)
);
CREATE TABLE `ap_match_event` (
`event_id` varchar(50) NOT NULL,
`event_name` text NOT NULL,
`event_start_date` date NOT NULL,
`event_end_date` date NOT NULL,
`event_venue` text NOT NULL,
PRIMARY KEY (`event_id`)
);
COMP1639 DATABASE ENGINEERING
23
(6): Create query for match player position (player placing) table
Result
(7): Create query for on match (matching) table
CREATE TABLE `ap_match_player_position` (
`match_id` varchar(50) NOT NULL,
`team_id` varchar(50) DEFAULT NULL,
`player_id` varchar(50) NOT NULL,
`position_id` varchar(50) NOT NULL,
KEY `match_id` (`match_id`),
KEY `player_id` (`player_id`),
KEY `position_id` (`position_id`),
KEY `team_id` (`team_id`),
CONSTRAINT `ap_match_player_position_ibfk_1` FOREIGN KEY (`match_id`) REFERENCES `ap_match` (`match_id`),
CONSTRAINT `ap_match_player_position_ibfk_2` FOREIGN KEY (`player_id`) REFERENCES `ap_player` (`player_id`),
CONSTRAINT `ap_match_player_position_ibfk_3` FOREIGN KEY (`position_id`) REFERENCES `ap_position` (`position_id`),
CONSTRAINT `ap_match_player_position_ibfk_4` FOREIGN KEY (`team_id`) REFERENCES `ap_team` (`team_id`)
);
COMP1639 DATABASE ENGINEERING
24
Result
(8): Create query for owner table
CREATE TABLE `ap_on_match` (
`match_id` varchar(50) NOT NULL,
`team_id` varchar(50) NOT NULL,
`on_match_goal` int(11) NOT NULL,
`on_match_time` varchar(50) NOT NULL,
KEY `match_id` (`match_id`),
KEY `player_id` (`team_id`),
CONSTRAINT `ap_on_match_ibfk_1` FOREIGN KEY (`match_id`) REFERENCES `ap_match` (`match_id`),
CONSTRAINT `ap_on_match_ibfk_2` FOREIGN KEY (`team_id`) REFERENCES `ap_team` (`team_id`)
);
CREATE TABLE `ap_owner` (
`owner_id` varchar(50) NOT NULL,
`owner_name` varchar(50) NOT NULL,
`owner_nrc` varchar(50) NOT NULL,
`owner_email` varchar(50) NOT NULL,
`owner_phone` int(11) NOT NULL,
`owner_birthday` date NOT NULL,
`owner_nationality` varchar(50) NOT NULL,
`owner_address` text NOT NULL,
`owner_personal_blog` varchar(50) NOT NULL,
PRIMARY KEY (`owner_id`)
);
COMP1639 DATABASE ENGINEERING
26
Result
CREATE TABLE `ap_player` (
`player_id` varchar(50) NOT NULL,
`team_id` varchar(50) NOT NULL,
`player_name` varchar(50) NOT NULL,
`player_number` int(11) NOT NULL,
`player_nrc` varchar(50) NOT NULL,
`player_email` varchar(50) NOT NULL,
`player_phone` int(11) NOT NULL,
`player_blood` varchar(10) NOT NULL,
`player_height_ft` double NOT NULL,
`player_weight_kg` double NOT NULL,
`player_birthday` date NOT NULL,
`player_nationality` varchar(50) NOT NULL,
`player_salary` double NOT NULL,
`player_reg_date` date NOT NULL,
PRIMARY KEY (`player_id`),
KEY `team_id` (`team_id`),
KEY `player` (`player_id`),
CONSTRAINT `ap_player_ibfk_1` FOREIGN KEY (`team_id`) REFERENCES `ap_team` (`team_id`)
);
COMP1639 DATABASE ENGINEERING
27
(10): Create query for player goal table
Result
(11): Create query for position table
Result
(12): Create query for round table
CREATE TABLE `ap_player_goal` (
`player_id` varchar(50) NOT NULL,
`match_id` varchar(50) NOT NULL,
`player_goal` int(11) NOT NULL,
KEY `player_id` (`player_id`),
KEY `match_id` (`match_id`),
CONSTRAINT `ap_player_goal_ibfk_1` FOREIGN KEY (`player_id`) REFERENCES `ap_player` (`player_id`),
CONSTRAINT `ap_player_goal_ibfk_2` FOREIGN KEY (`match_id`) REFERENCES `ap_match` (`match_id`)
);
CREATE TABLE `ap_position` (
`position_id` varchar(50) NOT NULL,
`position_type` varchar(100) NOT NULL,
PRIMARY KEY (`position_id`)
);
COMP1639 DATABASE ENGINEERING
28
Result
(13): Create query for team table
CREATE TABLE `ap_round` (
`match_id` varchar(50) NOT NULL,
`team_id` varchar(50) NOT NULL,
`position` enum('LEFT','RIGHT') NOT NULL,
KEY `match_id` (`match_id`),
KEY `team_id` (`team_id`),
CONSTRAINT `ap_round_ibfk_1` FOREIGN KEY (`match_id`) REFERENCES `ap_match` (`match_id`),
CONSTRAINT `ap_round_ibfk_2` FOREIGN KEY (`team_id`) REFERENCES `ap_team` (`team_id`)
);
COMP1639 DATABASE ENGINEERING
29
Result
(14): Create query for team score table
CREATE TABLE `ap_team` (
`team_id` varchar(50) NOT NULL,
`owner_id` varchar(50) NOT NULL,
`manager_id` varchar(50) NOT NULL,
`team_name` varchar(50) NOT NULL,
`team_email` varchar(50) NOT NULL,
`team_est_year` int(11) NOT NULL,
`team_headquarter` text NOT NULL,
`team_country` varchar(50) NOT NULL,
PRIMARY KEY (`team_id`),
KEY `owner_id` (`owner_id`),
KEY `manager_id` (`manager_id`),
CONSTRAINT `ap_team_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `ap_owner` (`owner_id`),
CONSTRAINT `ap_team_ibfk_2` FOREIGN KEY (`manager_id`) REFERENCES `ap_manager` (`manager_id`)
);
COMP1639 DATABASE ENGINEERING
30
Result
(15): Create query for transfer (player transfer on match) table
Result
CREATE TABLE `ap_team_score` (
`team_id` varchar(50) NOT NULL,
`match_id` varchar(50) NOT NULL,
`team_score` double NOT NULL,
KEY `team_id` (`team_id`),
KEY `match_id` (`match_id`),
CONSTRAINT `ap_team_score_ibfk_1` FOREIGN KEY (`team_id`) REFERENCES `ap_team` (`team_id`),
CONSTRAINT `ap_team_score_ibfk_2` FOREIGN KEY (`match_id`) REFERENCES `ap_match` (`match_id`)
);
CREATE TABLE `ap_transfer` (
`match_id` varchar(50) NOT NULL,
`player_id` varchar(50) NOT NULL,
`transfer_type` enum('OLD','NEW') NOT NULL,
KEY `match_id` (`match_id`),
KEY `player_id` (`player_id`),
CONSTRAINT `ap_transfer_ibfk_3` FOREIGN KEY (`match_id`) REFERENCES `ap_match` (`match_id`),
CONSTRAINT `ap_transfer_ibfk_5` FOREIGN KEY (`player_id`) REFERENCES `ap_player` (`player_id`)
);
COMP1639 DATABASE ENGINEERING
32
Population of database with data and values (16): Insert data to manager table
insert into `ap_manager`(`manager_id`,`manager_name`,`manager_nrc`,`manager_email`,`manager_phone`,`manager_birthday`,`manager_nationality`,`manager_address`,`manager_salary`,`manager_blog`) values ('MG01','Yuri','9/M(N)789456','yuri@outlook.com',9789654,'1994-11-28','JAPAN','No.22, Tera street, NW township',78965.12,'www.yuri.weebly.com'),
('MG02','Minnie','1/M(N)765744','minnie@gmail.coomm',9784521,'1994-06-22','MYANMAR','MCC institute compound, Mandalay',41258.56,'N/A'),
('MG03','Thiha Myat','2/W(N)452151','thiha@gmail.com',9785632,'1990-02-06','SOUTH KOREA','Block A, Tower 4D, MD trade center',82885.45,'N/A'),
('MG04','Hein Zarni','3/W(N)722226','zarni@outlook.com',9874125,'1989-02-07','USA','No.44, Judgernet street',98564.21,'N/A'),
('MG05','Michi Torea','9/M(N)111112','michi@gmail.com',9853145,'1994-06-07','UK','No22, Arial street, near KZ bank',62457.45,'N/A'),
('MG06','Shiina Yosuke','9/D(N)564544','shiina@flip.jp',9875655,'1994-06-28','UK','No.65, Nano street\r\n',69855.36,'www.shiina.flip.jp'),
('MG07','Pudge','9/M(N)123445','pudge@outlook.com',9787878,'1989-01-03','THAILAND','No.23, George commerical center',85657.22,'www.pudge.flip.jp'),
('MG08','Lwin Moe Aung','9/M(N)456666','lwinmoe@gmail.com',2555444,'1994-12-08','SINGAPORE','Room 1, Floor 4,Capital trade center',98556.24,'www.lwin.weebly.com'),
('MG09','Mario','2/M(N)734544','mario@mail.ru',9875566,'1989-01-28','ITALY','No.44B, Huge square township',85647.21,'N/A'),
('MG10','Jerry','1/M(N)733333','jerry@wash.com',9874366,'1994-06-28','FRENCH','Compound 4, Block A, Room 5, national tower',75652.24,'N/A'),
('MG11','Jack','7/T(N)754555','jack@mcc.com',2564444,'1989-06-28','BRAZIL','Floor 65, Room 2, Capital tower',87214.13,'www.jack.wordpress.org'),
('MG12','Ben Gates','9/G(N)784444','bengates@mail.ru',2136977,'1989-02-28','USA','Room 3, Floor 55, Empire state building',56884.26,'www.bengates.blogspot.com');
COMP1639 DATABASE ENGINEERING
33
(17): Insert data to judge team table
(18): Insert data to position table
insert into `ap_judge_team`(`judge_team_id`,`judge_team_name`,`judge_team_members`,`judge_contact`) values
('J1','PANDA SPORT JUDGE TEAM',13,'pandaj@gmail.com'),
('J2','WHITE MATCH SPORT JUDGE',11,'National sport center, US'),
('J3','NATIONAL FOOTBALL JUDGE TEAM',13,'965521'),
('J4','YOSUKE JUDGE TEAM',15,'yosuke@gmail.com'),
('J5','YOUKU JUDGE TEAM',14,'www.youku.wordpress.org');
COMP1639 DATABASE ENGINEERING
34
insert into `ap_position`(`position_id`,`position_type`) values ('CF','CENTRE FORWARD'),
('CHB','CENTRE HALF-BACK'),
('CHF','CENTRE HALF-FORWARD'),
('FB','FULL-BACK'),
('GK','GOALKEEPER'),
('LB','LEFT CORNER-BACK'),
('LCF','LEFT CORNER-FORWARD'),
('LHB','LEFT HALF-BACK'),
('LHF','LEFT HALF-FORWARD'),
('M','MIDFILEDER'),
('RB','RIGHT CORNER-BACK'),
('RCF','RIGHT CORNER-FORWARD'),
('RHB','RIGHT HALF-BACK'),
('RHF','RIGHT HALF-FORWARD');
COMP1639 DATABASE ENGINEERING
35
View, Trigger and Index (19): Create view for final result
CREATE
ALGORITHM = UNDEFINED
DEFINER = `root`@`localhost`
SQL SECURITY DEFINER
VIEW `aung_pyae_dbe_football`.`final_result` AS
SELECT
`ts`.`team_id` AS `team_id`,
`t`.`team_name` AS `team_name`,
SUM(`ts`.`team_score`) AS `team_score`
FROM
(`aung_pyae_dbe_football`.`ap_team_score` `ts`
JOIN `aung_pyae_dbe_football`.`ap_team` `t`)
WHERE
(`ts`.`team_id` = `t`.`team_id`)
GROUP BY `ts`.`team_id`;
COMP1639 DATABASE ENGINEERING
36
(20): Create view for player view
CREATE
ALGORITHM = UNDEFINED
DEFINER = `root`@`localhost`
SQL SECURITY DEFINER
VIEW `aung_pyae_dbe_football`.`player_view` AS
select `ap_player`.`player_name` AS `player_name`,sum(`ap_player_goal`.`player_goal`) AS `player_goal` from (`ap_player_goal` join `ap_player`) where (`ap_player_goal`.`player_id` = `ap_player`.`player_id`) group by `ap_player`.`player_id`CREATE VIEW player_view AS
SELECT
`ap_player`.`player_name` AS `player_name`,
SUM(`ap_player_goal`.`player_goal`) AS `player_score`
FROM
(`ap_player_goal`
JOIN `ap_player`)
WHERE
(`ap_player_goal`.`player_id` = `ap_player`.`player_id`)
GROUP BY `ap_player`.`player_id`;
COMP1639 DATABASE ENGINEERING
37
(21): Create view for team players
CREATE
ALGORITHM = UNDEFINED
DEFINER = `root`@`localhost`
SQL SECURITY DEFINER
VIEW `aung_pyae_dbe_football`.`team_players` AS
SELECT
`aung_pyae_dbe_football`.`ap_player`.`team_id` AS `team_id`,
COUNT(0) AS `team_players`
FROM
`aung_pyae_dbe_football`.`ap_player`
GROUP BY `aung_pyae_dbe_football`.`ap_player`.`team_id`;
COMP1639 DATABASE ENGINEERING
38
(22): Create trigger for player and team score calculation
CREATE DEFINER=`root`@`localhost` TRIGGER `ap_on_match_after_insert` AFTER INSERT ON `ap_on_match` FOR EACH ROW BEGIN
declare player varchar(50);
INSERT INTO ap_team_score VALUES (new.team_id,new.match_id,'3');
SELECT player_id FROM ap_match_player_position WHERE match_id=new.match_id AND team_id=new.team_id ORDER BY RAND() LIMIT 1 into player;
INSERT INTO ap_player_goal VALUES (player,new.match_id,'1');
END
COMP1639 DATABASE ENGINEERING
39
(23): Create trigger for player placing
(24): Create index on ap_player
CREATE DEFINER=`root`@`localhost` TRIGGER `ap_player_placing` AFTER INSERT ON `ap_round` FOR EACH ROW BEGIN
declare player_one varchar(50);
declare duplicate_player varchar(50);
declare total int;
declare p_position varchar(50);
myLoop: LOOP
select COUNT(player_id) from ap_match_player_position where match_id=new.match_id AND team_id=new.team_id into total;
SELECT `player_id` FROM ap_player WHERE `team_id`=new.team_id ORDER BY RAND() LIMIT 1 INTO player_one;
select position_id from ap_position ORDER BY RAND() LIMIT 1 INTO p_position;
INSERT INTO `ap_match_player_position` VALUES (new.match_id,new.team_id,player_one,p_position);
IF total=10 THEN
LEAVE myLoop;
END IF;
END LOOP myLoop;
END
CREATE INDEX player ON ap_player(player_id);
COMP1639 DATABASE ENGINEERING
40
SQL QUERIES
10 SQL queries that demonstrate for usefulness of database (1): a query that uses ORDER BY
Aim Used to know about teams with their related manager, owner and ordered with
established year descending. The age of team is calculated by YEAR function which is
counted from current date.
Query
Result Showing the result
SELECT
o.owner_name,
m.manager_name,
t.team_name,
t.team_est_year,
(YEAR(CURDATE()) - t.team_est_year) AS established
FROM
(ap_team t
JOIN ap_owner o, ap_manager m)
WHERE
t.owner_id = o.owner_id
AND t.manager_id = m.manager_id
ORDER BY established DESC;
COMP1639 DATABASE ENGINEERING
41
(2): a query that uses INNER JOINS
Aim Used to know players who plays with their national team.
Query
Result
(3): a query that uses aggregate functions
Aim Used to know what team has how many players to know which team is has the high
power of players.
SELECT
player_name,
player_nationality,
ap_team.team_name,
ap_team.team_country
FROM
ap_player
INNER JOIN
ap_team ON ap_player.player_nationality = ap_team.team_country
ORDER BY player_nationality;
COMP1639 DATABASE ENGINEERING
42
Query
Result
(4): a query that uses GROUP BY and HAVING clauses
Aim Counted with team players to in each team which are less than total of 14. This can be
used to show the teams which are few of total players.
SELECT
t.team_name, COUNT(p.team_id) AS total_players
FROM
ap_player p,
ap_team t
WHERE
p.team_id = t.team_id
GROUP BY t.team_name;
COMP1639 DATABASE ENGINEERING
43
Query
Result
(5): a query that uses a sub-query as a relation
Aim Used to show which players played in what position at what match. Players play in
match and they have their playing positions, and this query can show their positions with
related match.
Query
SELECT
t.team_name, COUNT(p.team_id) AS total_players
FROM
ap_player p,
ap_team t
WHERE
p.team_id = t.team_id
GROUP BY t.team_name
HAVING COUNT(p.team_id) < 14;
SELECT
p.player_id, p.player_name, mp.match_id, mp.position_id
FROM
(SELECT
*
FROM
ap_match_player_position) AS mp,
ap_player p
WHERE
p.player_id = mp.player_id;
COMP1639 DATABASE ENGINEERING
44
Result
(6): a query that uses a sub-query in the WHERE clause
Aim Select the players who have not been played in match as they are used for extra or spare
to use for transfer player in match and query is executed with sub-query.
Query
SELECT
p.player_id, p.player_name, p.player_nrc, p.team_id
FROM
ap_player p
WHERE
p.player_id NOT IN (SELECT
player_id
FROM
ap_match_player_position
GROUP BY team_id);
COMP1639 DATABASE ENGINEERING
45
Result
(7): a query stored as a VIEW
Aim Create a view to know the result score of each team which they have from the match.
Query
CREATE OR REPLACE VIEW final_result AS
SELECT
ts.team_id, t.team_name, SUM(ts.team_score) AS team_score
FROM
(ap_team_score ts
JOIN ap_team t)
WHERE
(ts.team_id = t.team_id)
GROUP BY ts.team_id;
COMP1639 DATABASE ENGINEERING
46
Result
(8): a query that uses a VIEW as a relation
Aim Used to calculate the skill percentage of each team calculated with each team score from
VIEW. The team on the top row of table has the highest score and skill percentage.
COMP1639 DATABASE ENGINEERING
47
Query
Result
(9): a query that uses partial matching in the WHERE clause
SELECT
a1.team_name,
a1.team_score,
CONCAT(a1.team_score * 100 / (SELECT
SUM(team_score)
FROM
final_result),
'%') AS skill_percentage
FROM
final_result a1,
final_result a2
WHERE
a1.team_score <= a2.team_score
OR (a1.team_score = a2.team_score
AND a1.team_id = a2.team_id)
GROUP BY a1.team_id , a1.team_score
ORDER BY a1.team_score DESC , a1.team_name DESC;
COMP1639 DATABASE ENGINEERING
48
Aim Used to show the result of player who has played in match witch match information,
player position and has the name keyword of lich, and two tables are connected to view
the result.
Query
Result
(10): a query that uses a SELF-JOIN
Aim Used self-join method to view the players who has the standard weight more than 60 Kg,
and has standard height. The player height is recorded with feet (ft.) in player table, but
this value is converted to international height unit, centimetre (cm) in query result.
SELECT
p.player_id,
p.player_name,
p.player_number,
pp.match_id,
pp.position_id
FROM
ap_player p,
ap_match_player_position pp
WHERE
p.player_id = pp.player_id
AND p.player_name LIKE '%lich%';
COMP1639 DATABASE ENGINEERING
49
Query
Result
SELECT DISTINCT
a.team_id,
a.player_name,
a.player_weight_kg,
CONCAT((a.player_height_ft * 30.48), ' cm') AS player_height
FROM
ap_player a,
ap_player b
WHERE
a.player_height_ft > b.player_height_ft
AND a.player_weight_kg > 60
ORDER BY player_height DESC;
COMP1639 DATABASE ENGINEERING
50
Future development report In this database system, I designed and developed for football management database system by using
RDBMS with one to one, multi sub class, and other common relationships. I used common special
database queries with functions and also trigger have looping for player placings. Views have
counting functions and also have the special timing functions of SQL are used to retrieve data.
If I will do this football management again, I want to design and develop the database system more
perfectly. The database design and tables will further be used for all web program and PC programs.
And some tables are need to complete for additional information such as logs and activities. Venues
will need to consider as single table and some other weak points on database such as player placing
and rounds need to reconsider or redesign more perfectly.
COMP1639 DATABASE ENGINEERING
51
Self-Assessment Sheet
%
No
Attempt
to Very
Poor
Poor Fair Good Very
Good Excellent
Conceptual
Database
design (EER)
20
Relational
Schema 10
Database
Implementation 20
Views and
Queries 20
Report 15
Data Used 5
Self-
assessment 5
Demonstration
Quality 5
Totals 100
COMP1639 DATABASE ENGINEERING
52
REFERENCES BOOKS AND JOURNALS
SQL Tutorial (2016) Available at: http://www.tutorialspoint.com/sql/ (Accessed: 20 November 2016).
In-line Citation:(SQL Tutorial, 2016)
WEBSITES
Relational database (2016) in Wikipedia. Available at:
https://en.wikipedia.org/wiki/Relational_database (Accessed: 20 November 2016). In-line
Citation:(Relational database, 2016)
keydata, 1 (2016) SQL - calculate percent to total. Available at: http://www.1keydata.com/sql/sql-
percent-to-total.html (Accessed: 20 November 2016). In-line Citation: (keydata, 2016)
SQL (structured query language) in one page: SQL.SU (no date) Available at: http://www.cheat-
sheets.org/sites/sql.su/ (Accessed: 20 November 2016). In-line Citation:(SQL (structured query
language) in one page: SQL.SU, no date)
● END OF COURSEWORK ●
Recommended