Q. Suppose your school management has decided to conduct cricket matches between students of class XI and Class XII. Students of each class are asked to join any one of the four teams — Team Titan, Team Rockers, Team Magnet and Team Hurricane. During summer vacations, various matches will be conducted between these teams. Help your sports teacher to do the following:
a) Create a database “Sports”.
b) Create a table “TEAM” with following considerations:
i) It should have a column TeamID for storing an integer value between 1 to 9, which refers to unique identification of a team.
ii) Each TeamID should have its associated name (TeamName), which should be a string of length not less than 10 characters.
c) Using table level constraint, make TeamID as primary key.
d) Show the structure of the table TEAM using SQL command.
e) As per the preferences of the students four teams were formed as given below. Insert these four rows in TEAM table:
Row 1: (1, Team Titan)
Row 2: (2, Team Rockers)
Row 3: (3, Team Magnet)
Row 4: (4, Team Hurricane)
f) Show the contents of the table TEAM.
g) Now create another table below. MATCH_DETAILS and insert data as shown in table. Choose appropriate domains and constraints for each attribute.
Table: MATCH_DETAILS
MatchID |
MatchDate |
FirstTeamID |
SecondTeamID |
FirstTeamScore |
SecondTeamScore |
M1 |
2018-07-17 |
1 |
2 |
90 |
86 |
M2 |
2018-07-18 |
3 |
4 |
45 |
48 |
M3 |
2018-07-19 |
1 |
3 |
78 |
56 |
M4 |
2018-07-19 |
2 |
4 |
56 |
67 |
M5 |
2018-07-20 |
1 |
4 |
32 |
87 |
M6 |
2018-07-21 |
2 |
3 |
67 |
51 |
h) Use the foreign key constraint in the MATCH_DETAILS table with reference to TEAM table so that MATCH_DETAILS table records score of teams existing in the TEAM table only.
Answer :-
a = Create database Sports ;
b = Create table Team ( TeamID int, TeamName char(10) ) ;
c = Alter table Team modify column TeamID int Primary key ;
d = Desc Team ;
e =
Insert into Team values (1, Team Titan) ;
Insert into Team values (2, Team Rockers) ;
Insert into Team values (3, Team Magnet) ;
Insert into Team values (4, Team Hurricane) ;
f = Select * from Team ;
g = Create table MATCH_DETAILS ( MatchID char(2) , MatchDate date , FirstTeamID int , SecondTeamID int , FirstTeamScore int , SecondTeamScore int ) ;
insert into Match_details values( “M1” , 2018-07-17 , 1 ,2, 90, 86 ) ;
insert into Match_details values( “M2”, 2018-07-18, 3, 4, 45 , 48 ) ;
insert into Match_details values( “M3” , 2018-07-19 , 1 , 3 , 78 , 56 ) ;
insert into Match_details values( “M4” , 2018-07-19 , 2 , 4 , 56 ,67 ) ;
insert into Match_details values( “M5“ , 2018-07-20 , 1 , 4 , 32, 87 ) ;
insert into Match_details values( “M6”, 2018-07-21 , 2 , 3 , 67, 51 ) ;
h =
ALTER TABLE Match_details
ADD FOREIGN KEY ( FirstTeamID ) REFERENCES Team( TeamID );
ALTER TABLE Match_details
ADD FOREIGN KEY ( SecondTeamID ) REFERENCES Team( TeamID );
Post a Comment
You can help us by Clicking on ads. ^_^
Please do not send spam comment : )