DATABASE MANAGEMENT SYSTEMS PROJECT REVIEW-1 PROJECT BY: HRITISHA- 18BIT0226 SHREYA CHATTERJEE- 18BIT0251 EMMADI DIVYA SRUJANA-18BIT0257 Slot: F2+TF2 L35+L36 TOPIC: Cricket World Cup REVIEW : 1 Project Name : Cricket World Cup Introduction : Our DBMS project is based on Cricket World Cup management. It provides various information about the various teams participating in the World Cup, in which all the major countries participate. It also provides us with information about the various players participating in the tournament . The database contains details of players, coaches and umpires among others. All the useful information about the entire World Cup can be found here. Data Requirements: Entities: 1) Team is an entity type which has many attributes like Team Name which uses the data type varchar. Every team has been given a Team ID which is the primary key which is of data type varchar. Team Ranking, Number of Batsmen and Number of Bowlers are of the data type number. There is another attribute - Wicketkeeper which is of multivalued type and accepts varchar data type. Primary key cannot have null value. 2) Players is an entity type which has an attribute – Player Name which is of the data type varchar. It has a primary key, Player ID, which cannot have null value. It has a foreign key, Team ID which is the primary key of the entity, Team. There is a complex attribute, Number of matches played, which comprises of Number of Test Matches, Number of T20 Matches, Number of World Cup Matches and Number of ODIs. 3) Batsman is an entity type which has the attributes – Number of sixes hit, Number of Fours hit, the batting average, and the total runs scored. All of these attributes are of the data type number. 4) Bowler is an entity type which has the attribute – type of batsman with varchar data type. It also includes number of wickets and economy which are of the data type number. 5) Umpire is an entity type which has the attributes name and country of origin of data type varchar. The primary key of this is Umpire Id which is of varchar data type. It also has an attribute Number of matches of data type number. 6) Coach is an entity type with a foreign key, Team ID, which is a primary key of entity type, Team. It has a primary key, Coach ID, of data type varchar. It also has another attribute of data type varchar, Name. 7) Captain is an entity type with a primary key, Captain ID of data type varchar. It has two foreign keys, i) Player id from table Players and ii) Team ID from table Team. Number of years of captaincy and Number of wins are also attributes of this table of data type number. 8) Matches is an entity type with a primary key, match ID, of varchar data type. It has attributes like Team1 Name, Team2 Name, Stadium, Winner Team and Loser Team of data type varchar. Match date is an attribute which uses the datatype date. Match time is an attribute which is of the data type time. Relationships: Cricket player plays in team (N-1) A cricket player can play in only one team but a team can have many players in it but a team must have players in it. So, the relationship becomes (N-1). Coach manages team(1-N) Coach can manage a single team, but each team can have many coaches (like batting coach, fielding coach, bowling coach). But it is compulsory for a team to have a coach. So, the relationship is 1-N Team plays match(M-N) Team can play many matches and a match can be played by two teams. So, the relationship is M-N. Matches are umpired by Umpire(M-N) An umpire can umpire in many matches and a match can have two umpires. So, the relationship is M-N. Team headed by a Captain (1-1) A team has 1 captain and a captain is from single team only. So the relationship is 1-1. Functional Requirements: 1) VIEWER System must allow users to login if they enter the correct login id and password. The users must be able to see the player details of each player in the database. Scores of each match must be visible. Match date and venue should be displayed on the login if the users seek for it. System should display the complete roster of a team including the captain and the players playing in the top 11 and the current rank of the team. The details of the coach must also be available to the users. Referees and their details are also important as the players and the viewers want to see the best referees managing their team’s match. Each player’s statistics should also be available like total runs , number of matches played etc. System should display data on each match which has been scored in the duration of the entire tournament. System should allow fixtures to be searched and the date should also be available. BASIC ANALOGY: • • • • • • • • • • • • View the website with a browser. Login to the website. View all teams. View all players of a team. View all batsmen in the tournament. View all bowlers in the tournament. View all match reports in a season. View statistics of a player (all time). View coach details. View umpire details. View Match details. View ranking of each team View Player information per match: a) Number of matches b) Total runs c) Total wickets View all match details: i. ii. iii. iv. v. vi. vii. viii. Team 1 Team 2 Umpire Winner Date Time Stadium Rank of teams after match 2) ADMINISTRATOR Administrator is in charge of creating the website which is used to access the database. Administrator has all the privileges of the user but has the authority to add and remove data from the database which the user cannot do. Administrator is responsible for creating different user accounts and assigning the id and password. Administrators are the one who generate the fixtures and update them in the database. They should be allowed to enter the team name of home and away teams. He should have the authority to enter and modify the match details like time and venue in case the need to be changed. If any player has been punished for bad behaviour or other reasons and cannot play in the World Cup anymore the administrator should be able to delete the data from the database. The rank of every team must keep being modified after each match. After a team is eliminated or disqualified the administrator should be able to delete the entire team’s record. BASIC ANALOGY: • • • • • • • • Create website. Generate login ID for viewer. Design website. Display different menus. Create World Cup. Display Team Name. Display Team Captain. Display Team Squad. View Player information per match: a) Number of matches b) Total runs c) Total wickets REMOVAL OF OLD DATA: i. ii. iii. If any team gets disqualified, then their data needs to be removed from the database. If a player gets injured during the World Cup and is unable to play further, then their data needs to be removed from the database. If any match gets cancelled due to unforeseen circumstances, then the particular match details should be removed. MODIFICATION OF DATA: i. ii. iii. After every match the existing ranks of every team should be modified. After every match, the statistics of every player should be updated. Due to unfavourable weather conditions, a match might get delayed. Hence, the match timings need to be changed. RETRIEVAL OF DATA: i) View information of every Team: Before the start of a new match, we have to retrieve the Team record like: a) b) c) d) e) f) g) Team Name Number of Batsman Number of Bowlers Wicketkeeper Number of Wins Number of Losses Names of Players ii) View information of every Match: After every match, we have to retrieve the Match details like: a) b) c) d) e) iii) First Team Name Second Team Name Umpire Winner Loser View Score Board: After every match, we have to retrieve the ranking order of teams : a) Rank of each team b) Team name iv) View the captain of each team: During the toss, we need to retrieve the data of the captain a) Name of captain b) Number of wins under his captaincy c) Years of captaincy ER MODEL along with key constraints, participation constraints and cardinality constraints: DATABASE MANAGEMENT SYSTEMS (ITE1003) REVIEW 2 BY: HRITISHA 18BIT0226 SHREYA CHATTERJEE 18BIT0251 EMMADI DIVYA SRUJANA 18BIT0257 QUESTION 4 : QUESTION 5: TABLES • • • • • • • • • Team Wicket_Keeper Umpire Player Coach Captain Matches Plays Umpired_By CODE TO CREATE TABLES: create table TEAM( team_id varchar(30) primary key, team_rank number(3), team_name varchar(20) not null, country_name varchar(20), no_of_wins number(3), no_of_loses number(3), no_of_draws number(3), no_of_bowlers number(2), no_of_batsmans number(2) ); create table WICKET_KEEPER( team_id references TEAM, wk_name varchar(30) ); create table UMPIRE( umpire_id varchar(30) primary key, umpire_name varchar(30), no_of_matches number(4), country varchar(20) ); create table PLAYER( player_id varchar(30) primary key, team_id references TEAM, no_of_worldcups number(2), number_of_matches number(3), batting_average number(3), no_of_sixes number(3), no_of_fours number(3), no_of_totalruns number(4), no_of_t20 number(3), no_of_odi number(3), no_of_test number(3), no_of_wickets number(2), type_of_bowler varchar(30), economy number(3) ); create table COACH( coach_id varchar(30) primary key, team_id references TEAM, coach_name varchar(30) ); create table CAPTAIN( captain_id varchar(30) primary key, captain_name varchar(30), team_id references TEAM, player_id varchar(30), year_of_captaincy number(2), no_of_wins number(4) ); create table MATCHES( match_id varchar(20) primary key, match_date date, match_time timestamp(0), team_1_name varchar(30), team_2_name varchar(30), loser varchar(30), winner varchar(30), stadium varchar(30), umpire_id references umpire ); create table PLAYS( team_id references TEAM, match_id references MATCHES ); create table UMPIRED_BY( match_id references MATCHES, umpire_id references UMPIRE ); TABLE TEAM: TABLE WICKET_KEEPER: TABLE UMPIRE: TABLE PLAYER: TABLE COACH: TABLE CAPTAIN: TABLE MATCHES: TABLE PLAYS: TABLE UMPIRED_BY: CODE TO INSERT VALUES TO TABLE: TEAM VALUES insert into team values( 'IND1221', 1, 'MEN IN BLUE','INDIA', 5, 1, 0, 6, 7 ); Insert into team values( 'AUS2174', 4, 'KANGAROO','AUSTRAILA', 3, 3, 0, 5, 6 ); Insert into team values( 'SA5412', 3, 'PROTEA','SOUTH AFRICA', 3, 2, 1, 8, 5 ); Insert into team values( 'NZ5687', 2, 'BLACK CAPS','NEW ZEALAND', 4, 2, 0, 6, 7 ); Insert into team values( 'BAN9852', 5, 'TIGERS','BANGLADESH', 2, 4 , 0, 7, 7 ); UMPIRE VALUES insert into UMPIRE values ( 'UMP41002', 'Kumar Dharmasena', 103, 'Sri Lanka' ); insert into UMPIRE values ( 'UMP74101', 'Aleem Dar', 207, 'Pakistan' ); insert into UMPIRE values ( 'Ump52410', 'Anil Chaudhary', 19, 'India' ); insert into UMPIRE values ( 'UMP85201', 'Ian Gould', 140, 'England' ); insert into UMPIRE values ( 'UMP55200', 'Tony Hill', 96, 'New Zealand' ); COACH VALUES insert into COACH values( 'CH417', 'IND1221', 'RAVI SHASTRI' ); insert into COACH values( 'CH140', 'AUS2174', 'JUSTIN LANGER' ); insert into COACH values( 'CH223', 'SA5412', 'OTTIS GIBSON' ); insert into COACH values( 'CH398', 'NZ5687', 'GARY STEAD' ); insert into COACH values( 'CH748', 'BAN9852', 'RUSSEL DOMINGO' ); CAPTAIN VALUES insert into captain values( 'CAP11452', 'MS DHONI', 'IND1221','PLR44567', 4,56 ); insert into captain values( 'CAP21478', 'DALE STEYN', 'SA5412','PLR10235', 7,74 ); insert into captain values( 'CAP30214', 'MICHAEL CLARKE', 'AUS2174','PLR74138', 9,100 ); insert into captain values( 'CAP14789', 'TAMIM IQBAL', 'BAN9852','PLR89562',2,20 ); insert into captain values( 'CAP36957', 'ROSS TAYLOR', 'NZ5687','PLR957417', 5,85 ); MATCHES VALUES insert into MATCHES values( 'MAT101',to_date('12-03-2011','dd-mmyyyy'),to_timestamp('15:30','hh24:mi'),'India','Bangladesh','Bangladesh','India','Feroz Shah Kotla','UMP55200' ); insert into MATCHES values( 'MAT201',to_date('15-03-2011','dd-mmyyyy'),to_timestamp('9:30','hh24:mi'),'England','Australia','England','Australia','Eden Gardens','UMP41002' ); insert into MATCHES values( 'MAT301',to_date('21-03-2011','dd-mm-yyyy'),to_timestamp('11:30','hh24:mi'),'Sri Lanka','Bangladesh','Bangladesh','Sri Lanka','M.A. Chidambaram','UMP74101' ); insert into MATCHES values( 'MAT401',to_date('23-03-2011','dd-mm-yyyy'),to_timestamp('15:30','hh24:mi'),'New Zealand','South Africa','South Africa','New Zealand','Sardar Patel','UMP85201' ); insert into MATCHES values( 'MAT501',to_date('26-03-2011','dd-mmyyyy'),to_timestamp('8:30','hh24:mi'),'England','India','England','India','Wankhede','Ump524 10' ); PLAYER VALUES insert into PLAYER values ( 'PLR17410', 'IND1221', 2, 13, 58,7,24,800,74,120,20,1,'medium',3.2 ); insert into PLAYER values ( 'PLR74203', 'AUS2174', 1, 6, 67, 10,39,463,41,210,140 ,1,'slow',8.5 ); insert into PLAYER values ( 'PLR45987', 'SA5412', 3, 4, 99, 4, 47,985, 24,63,65,1,'medium-slow',11.2 ); insert into PLAYER values ( 'PLR20147', 'NZ5687', 1, 12, 12, 1, 3,85, 52 ,10,74,1,'legspin',18.3 ); insert into PLAYER values ( 'PLR65200', 'BAN9852', 2, 9, 4, 0,1 ,21,77, 30,2,1,'fast',17.3 ); UMPIRED_BY VALUES insert into Umpired_by values( 'MAT501','UMP55200' ); insert into Umpired_by values( 'MAT301','Ump52410' ); insert into Umpired_by values( 'MAT101','UMP41002' ); insert into Umpired_by values( 'MAT401','UMP74101' ); insert into Umpired_by values( 'MAT201','Ump52410' ); PLAYS VALUES insert into Plays values( 'IND1221','MAT101' ); insert into Plays values( 'AUS2174','MAT201' ); insert into Plays values( 'BAN9852','MAT301' ); insert into Plays values( 'NZ5687','MAT401' ); insert into Plays values( 'IND1221','MAT501' ); WICKET_KEEPER VALUES insert into WICKET_KEEPER values( 'IND1221','MS Dhoni' ); insert into WICKET_KEEPER values( 'IND1221','Dinesh Kartik' ); insert into WICKET_KEEPER values( 'AUS2174','Tim Lee' ); insert into WICKET_KEEPER values( 'AUS2174','Peter Hegward' ); insert into WICKET_KEEPER values( 'AUS2174','Hefer Kingsly' ); DATABASE MANAGEMENT SYSTEMS (ITE1003) REVIEW 3 BY: HRITISHA 18BIT0226 SHREYA CHATTERJEE 18BIT0251 EMMADI DIVYA SRUJANA 18BIT0257 QUESTION 6 Write down the necessary SQL statements for implementation of functional requirements through SQL query, delete and update statement. UPDATE 1. Add column of total matches in the table TEAM. Update the rows using total matches= number of WNS+ number of LOSES + number of DRAWS. CODE: alter table team add total_matches number(5); update team set total_matches=no_of_draws + no_of_wins + no_of_loses; 2. Add column named ‘PLAYER_NAME’ in table PLAYER. Using interactive updation. CODE: 3. alter table player add player_name varchar(20); 4. update player set player_name = '&player_name' where player_id = '&player_id'; OUTPUT: SQL QUERIES USING JOIN/NESTING/SET OPERATIONS 1. Display the name of the umpires who have not umpired matches in eden gardens. CODE: select umpire_name from umpire minus select umpire_name from umpire where umpire_id in(select umpire_id from matches where stadium='Eden Gardens'); select umpire_name from umpire minus select umpire_name from umpire natural join mat ches where stadium='Wankhede'; OUTPUT: 2. (a)Display the country whose players have batting average greater than 60. (b) Display the country whose players donot have batting average greater than 60. CODE: select country_name from team where team_id in(select team_id from player where batting_average >60); select country_name from team natural join player where batting_average>60; select country_name from team minus select country_name from team where team_id in(s elect team_id from player where batting_average >60); OUTPUT: 3. Display name of coach who has coached a player with total_runs greater than 500; CODE: select distinct coach_name from coach where team_id in(select team_id from player where no_of_totalruns>500 ); select distinct coach_name from coach inner join player on coach.team_id = player.team_id where(player.no_of_totalruns>500); select distinct coach_name from coach minus select distinct coach_name from coach wh ere team_id in(select team_id from player where no_of_totalruns>500 ); OUTPUT: 4. Display name of wicket keeper who is also the captain of his team. CODE: select wk_name from WICKET_KEEPER where team_id in(select team_id from captain where captain_name=wk_name); select wk_name from WICKET_KEEPER natural join captain where captain_name =wk_name; select wk_name from WICKET_KEEPER minus select wk_name from WICKET_KEEPER where tea m_id in(select team_id from captain where captain_name=wk_name); OUTPUT: GROUP BY HAVING CLAUSE QUERY Display the name of players who have same bowling action CODE: select player_id, upper(player_name) from player where type_of_bowler in(select type _of_bowler from player group by type_of_bowler having count(*)>1); OUTPUT: DELETE: 1. Deleting the column number_of_matches. CODE: alter table player drop column no_of_matches; delete from coach where coach_id='CH596'; OUTPUT: Deletion with embedded select delete from player where team_id in(select team_id from team where countr y_name='Australia'); QUESTION 7 Define and implement one PL/SQL function and one PL/SQL procedure appropriate for the database under consideration. PROCEDURE: User wants to predict the competition level of the next match by fetching the player details of a particular team. Use PL/SQL procedure to execute the same. FUNCTION: User wants to book the tickets of an upcoming match Create a PL/SQL function to display the stadium name on entering the desired Match. QUESTION 8 Define two business rules appropriate for the database under consideration and implement the rules using trigger. TRIGGER 1 When a team is eliminated do the necessary process and update the elimination table. CODE: create table elimination ( teamid varchar(10) primary key, cntry_name varchar(15), rankk number(2), teamName varchar(15), noLoses number(2) ); set serveroutput on create or replace trigger trig2 after delete on team referencing new as new old as old for each row begin insert into elimination values (:OLD.team_id ,:OLD.country_name ,:OLD.team_rank ,:OLD.team_name,:OLD.no_of_loses); END; / delete from team where team_id='BAN9852'; select *from elimination ; OUTPUT (NEXT PAGE) TRIGGER 2 Due to some malpractices a team was banned for 2 years . After 2 years when it came back the board of cricket council order to change the team_ID because of some reasons CODE: Create or replace trigger reference1 after update on team for each row begin update player set team_id=:new.team_id where team_id=:old.team_id; update coach set team_id=:new.team_id where team_id=:old.team_id; update captain set team_id=:new.team_id where team_id=:old.team_id; update plays set team_id=:new.team_id where team_id=:old.team_id; update wicket_keeper set team_id=:new.team_id where team_id=:old.team_id; end; / update team set team_id= 'AUS7895' where team_id='AUS2174'; select * from player; OUTPUT