1. Trang chủ
  2. » Công Nghệ Thông Tin

DBI ASSIGNMENT REPORT Student Nguyen Vu Minh Student’s Roll Number SE05309 Class SE1208 Subject Introduction to Databases ( DBI 202) Instructor Ngo Tung Son Table of Contents A Background 7 I General.

61 126 1

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 61
Dung lượng 2,31 MB

Nội dung

DBI ASSIGNMENT REPORT Student Nguyen Vu Minh Student’s Roll Number SE05309 Class SE1208 Subject Introduction to Databases ( DBI 202) Instructor Ngo Tung Son Table of Contents A Background 7 I General.

DBI ASSIGNMENT REPORT Student: Nguyen Vu Minh SE05309 Student’s Roll Number: Class: SE1208 Subject: Introductionto Databases( DBI 202) Instructor:Ngo Tung Son Table of Contents Table of Image Figure 1: The Premier League Information Figure 2: Premier League Season information Figure 3: Premier League Fixtures 10 Figure 4: Premier League Results 11 Figure 5: Premier League 2017 – 2018 Tables 12 Figure 6: Premier League Clubs 13 Figure 7: Premier League Players 14 Figure 8: Premier League Managers 15 Figure 9: Premier League Referees 16 Figure 10: Premier League Match Statistics 17 Figure 11: Simplified ERD for Premier League 2017 – 2018 19 Figure 12: Full ERD for Premier League 2017 – 2018 20 Figure 13: Club entity 21 Figure 14: Player entity 22 Figure 15: Match player entity 23 Page Figure 16: Foul entity 24 Figure 17: Card entity 24 Figure 18: Goal entity 25 Figure 21: Stadium entity 28 Figure 22: Manager entity 28 Figure 23: Player – Club Relationship 29 Figure 24: Manager – Club Relationship 30 Figure 25: Player – MatchPlayer - Match Relationship 31 Figure 26: MatchPlayer – Foul – Card- Goal Relationship 32 Figure 27: Stadium – Club - Match Relationship 33 Figure 28: Match - Referee Relationship 34 Figure 29: Logical Design 40 Figure 30: Result of query using order by 56 Figure 31: Result of query using INNER JOIN 57 Figure 32: Result of query using INNER JOIN 58 Figure 33: Result of query using aggregate function 59 Figure 34: Result of query using GROUP BY and HAVING clause 60 Figure 35: Result of query using sub query as relation 61 Figure 36: Result of query using sub query in where clause 62 Figure 37: Result of query using sub query in where clause 62 Page Figure 38: Result of query using partial matching in WHERE clause 63 Figure 39: Result of query using self - join 64 Figure 40: Store procedure 65 Figure 41: Trigger 66 Page A Background I General Design and develop a database system for a sport tournament season The database must consist of at least six tables populated with data The database is to support queries that would typically be submitted to the system for the topical chosen area Using Chen’s Notation for Entity Relationship Diagram (ERD) Map the EER model into a relational data model normalized at least rd normal Form Using appropriate SQL commands create a set of database tables in MS SQL Server 2008+ You should also show all constraints used in the creation of the tables II Specification: Your database must contain one view, one trigger, on store procedure and an index (describe why) Create 10 sample queries that demonstrate the expressiveness of your database system Your queries must demonstrate different aspects of the system III Destination Design and develop a database system for English Premier League 2017 – 2018 IV Tools Microsoft SQL Database Management Studio 2016 Microsoft Visio 2016 Professional Microsoft Word 2016 Professional https://www.generatedata.com Page B Preview I Introduce The Premier League The Premier League is an English professional league for men's association football clubs At the top of the English football league system, it is the country's primary football competition Contested by 20 clubs, it operates on a system of promotion and relegation with the English Football League Welsh clubs that compete in the English football league system can also qualify Welsh clubs that compete in the English football league system can also qualify The Premier League is a corporation in which the 20 member clubs act as shareholders Seasons run from August to May Teams play 38 matches each (playing each team in the league twice, home and away), totaling 380 matches in the season Most games are played on Saturday and Sunday afternoons; others during weekday evenings It is colloquially known as the Premiership and outside the UK it is commonly referred to as the English Premier League (EPL) In total, 49 clubs have competed since the inception of the Premier League in 1992 Six of them have won the title: Manchester United (13), Chelsea (5), Arsenal (3), Manchester City (2), Blackburn Rovers (1) and Leicester City (1) Figure 1: The Premier League Information (Source: Wikipedia (https://en.wikipedia.org/wiki/Premier_League)) Page II Information for a Premier League Season A Premier League season contains a lot of information that must be stored Below is the most necessary information: • Fixtures • Results • Tables • Clubs • Players • Managers • Referees • Match statistics Figure 2: Premier League Season information In fact, a Premier League season has much more information than above one such as broadcast rights, transfers, tickets, safeguarding or lots of other However, to simplify the work of designing and developing databases system as well as the structure of database, I will only concentrate on the main information that I listed above (Source: https://www.premierleague.com/home) Fixtures In order to control the matches time for broadcast, transfers purpose or fitting with all other events like Christmas, New Years, World Cup Qualifiers, etc., before the first game, the fixtures are made for a whole season – usually from August to May The fixtures contain lots of records Each record includes information of a match that has been scheduled: home team, guest team, date and time that the match will be played, the stadium where the match will be hold Page Figure 3: Premier League Fixtures (Source: https://www.premierleague.com/fixtures) Results: Results is one of the most information of a football match The results are the status win, lose or draw, the score of home and away team The winner will receive points, the looser will get no point and if the result is draw, both two team get point Page Figure 4: Premier League Results (Source: https://www.premierleague.com/results) Tables After a match, each teach will get their corresponding point (3 points if win, point if draw and point if lose) This point will be statistics to create tables The tables will be updated after a match and will show ranking of each team in the league The tables usually contain club name with their position, how many game that played, games they won, drawn and lost, number of goals for, goal again, goal different, their point and their recently form Page Figure 5: Premier League 2017 – 2018 Tables (Source: https://www.premierleague.com/tables) Clubs In the Premier League history, there are many different clubs that had competed at this league, but in this assignment, I will only concern about the most recently season, the Premier League 2017 – 2018 So, there are only have 20 clubs compete at this league this season A club information includes their name, their address, their stadium, their CEO, etc Page 10 Name NVARCHAR(50) NOT NULL, Nationality NVARCHAR(50) NOT NULL ) Club table CREATE TABLE Club ( ClubID INT PRIMARY KEY, ClubName NVARCHAR(50) NOT NULL, StadiumID INT NOT NULL, CONSTRAINT Club_FK_Stadium FOREIGN KEY (StadiumID) REFERENCES Stadium(StadiumID) ) Player_Club table CREATE TABLE Player_Club ( PlayerID INT NOT NULL, ClubID INT NOT NULL, StartDate DATE NOT NULL, EndDate DATE NOT NULL, Salary FLOAT NOT NULL, ShirtNo INT NOT NULL CONSTRAINT Player_Club_PK PRIMARY KEY (PlayerID, ClubID), CONSTRAINT Player_Club_FK_Player FOREIGN KEY (PlayerID) REFERENCES Player(PlayerID), CONSTRAINT Player_Club_FK_Club FOREIGN KEY (ClubID) REFERENCES Club(ClubID), CONSTRAINT Player_Club_CHK CHECK (ShirtNo >= AND EndDate > StartDate AND Salary > 0) ) Manager_Club table CREATE TABLE Manager_Club ( ManagerID INT NOT NULL, ClubID INT NOT NULL, StartDate DATE NOT NULL, EndDate DATE NOT NULL CONSTRAINT Manager_Club_PK PRIMARY KEY (ManagerID, ClubID), Page 47 CONSTRAINT Manager_Club_FK_Manager FOREIGN KEY (ManagerID) REFERENCES Manager(ManagerID), CONSTRAINT Manager_Club_FK_Club FOREIGN KEY (ClubID) REFERENCES Club(ClubID), CONSTRAINT Manager_Club_CHK CHECK (EndDate > StartDate) ) Match table CREATE TABLE Match ( HostID INT NOT NULL, GuestID INT NOT NULL, Date DATE NOT NULL, Status NVARCHAR(10) NOT NULL, RefereeID INT NOT NULL CONSTRAINT Match_PK PRIMARY KEY (HostID, GuestID, Date), CONSTRAINT Match_FK_HostClub FOREIGN KEY (HostID) REFERENCES Club(ClubID), CONSTRAINT Match_FK_GuestClub FOREIGN KEY (GuestID) REFERENCES Club(ClubID), CONSTRAINT Match_FK_Referee FOREIGN KEY (RefereeID) REFERENCES Referee(RefereeID), CONSTRAINT Match_CHK CHECK (Status IN ('Scheduled', 'Playing', 'Finished', 'Postponed')) ) 10 MatchPlayer table CREATE TABLE MatchPlayer ( ID INT PRIMARY KEY, isMain BIT NOT NULL, PlayerID INT NOT NULL, HostID INT NOT NULL, GuestID INT NOT NULL, Date DATE NOT NULL, SubBy INT, SubTime INT, CONSTRAINT MatchPlayer_FK_Player FOREIGN KEY (PlayerID) REFERENCES Player(PlayerID), CONSTRAINT MatchPlayer_FK_Match FOREIGN KEY Page 48 (HostID, GuestID, Date) REFERENCES Match(HostID, GuestID, Date), CONSTRAINT MatchPlayer_FK_MatchPlayer FOREIGN KEY (SubBy) REFERENCES MatchPlayer(ID) ) 11 Foul table CREATE TABLE Foul ( ID INT PRIMARY KEY, Type NVARCHAR(100) NOT NULL, CommitBy INT NOT NULL, ReceiveBy INT, CardID INT CONSTRAINT Foul_FK_CommitPlayer FOREIGN KEY (CommitBy) REFERENCES MatchPlayer(ID), CONSTRAINT Foul_FK_ReceivePlayer FOREIGN KEY (ReceiveBy) REFERENCES MatchPlayer(ID), CONSTRAINT Foul_FK_Card FOREIGN KEY (CardID) REFERENCES Card(ID) ) 12 Goal table CREATE TABLE Goal ( GoalID INT PRIMARY KEY, Minute INT NOT NULL, Offset INT, Type NVARCHAR(10) NOT NULL, ScoreBy INT NOT NULL, AssistBy INT CONSTRAINT Goal_FK_ScorePlayer FOREIGN KEY (ScoreBy) REFERENCES MatchPlayer(ID), CONSTRAINT Goal_FK_AssistPlayer FOREIGN KEY (AssistBy) REFERENCES MatchPlayer(ID), CONSTRAINT Goal_CHK CHECK (Minute >=1 and Minute 30 - Result: Figure 33: Result of query using aggregate function Page 53 Queries using GROUP BY and HAVING clauses: - Question: Display number of players born between 1985 and 1995 for each year The first column is the year and the second column is number of players was born in this year Query: SELECT YEAR(DOB) as [Year], COUNT (*) as NumPlayer FROM Player GROUP BY YEAR(DOB) HAVING YEAR(DOB) >=1985 AND YEAR(DOB) BEGIN RAISERROR('You can not sub more than players', 1, 1); ROLLBACK TRANSACTION END END - Test trigger: UPDATE MatchPlayer SET SubBy = 51 WHERE ID = 48 Run successfully UPDATE MatchPlayer SET SubBy = 51, SubTime = 82 Page 60 WHERE ID = 46 Figure 41: Trigger Page 61 ... distances) has ID as Primary key - Manager (ManagerID, Name, Nationality) has ManagerID as Primary key - Stadium (StadiumID, Name, Address, Capacity) has StadiumID as Primary key - Referee (RefereeID,... Database Diagram Figure 29: Logical Design III Table Analysis Stadium: Attributes Data type Allow null Page 36 StadiumID (Primary Key) INT No Name NVARCHAR(50) No Address NVARCHAR(150) No Capacity... StadiumID is primary key 10 Manager Manager Name ManagerID Nationality Figure 22: Manager entity - Definition: Each club is coached by a manager Actually, a club could have many manager (1 main

Ngày đăng: 08/11/2022, 00:02

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN

w