Database Worksheet
Database Worksheet
1
18. A table, ITEM has been created in a database with the following fields:
ITEMCODE, ITEMNAME, QTY, PRICE
Give the SQL command to add a new field, DISCOUNT (of type Integer) to the
ITEM table.
19. Categorize following commands into DDL and DML commands?
INSERT INTO, DROP TABLE, ALTER TABLE, UPDATE...SET
20. Differentiate between the terms Attribute and Domain in the context of
Relational Data Model.
21. Differentiate between Candidate Key and Primary Key in the context
Relational Database Model.
22. A SQL table ITEMS contains the following columns:
TNO, INAME, QUANTITY, PRICE, DISCOUNT
Write the SQL command to remove the column DISCOUNT from the table.
23. Categorize the following SQL commands into DDL and DML:
CREATE, UPDATE, INSERT, DROP
24. Write an output for SQL queries (i) to (iii), which are based on the table:
STUDENT given below:
Table: STUDENT
(i) SELECT COUNT (*), City FROM STUDENT GROUP BY CITY HAVING
COUNT (*)>1;
(ii) SELECT MAX (DOB), MIN (DOB) FROM STUDENT;
(iii) SELECT NAME, GENDER FROM STUDENT WHERE CITY=”Delhi”;
2
25. A departmental store MyStore is considering to maintain their inventory
using SQL to store the data. As a database administer, Abhay has decided that :
• Name of the database - mystore
• Name of the table - STORE
• The attributes of STORE are as follows:
ItemNo - numeric
ItemName – character of size 20
Scode - numeric
Quantity – numeric
3
26. Write the outputs of the SQL queries (i) to (iii) based on the relations
Teacher and Posting given below:
4
i. To show all information about the teacher of History department.
ii. To list the names of female teachers who are in Mathematics department.
iii. To list the names of all teachers with their date of joining in ascending
order.
iv. To display teacher’s name, salary, age for male teachers only.
v. To display name, bonus for each teacher where bonus is 10% of salary.
28. Write the output of the queries (a) to (d) based on the table, Furniture
given below:
5
29. Consider the table, MOVIEDETAILS given below:
Which field will be considered as the foreign key if the tables MOVIEDETAILS
and SCHEDULE are related in a database?
30. Charu has to create a database named MYEARTH in MYSQL. She now needs
to create a table named CITY in the database to store the records of various
cities across the globe. The table CITY has the following structure:
Table: CITY
FIELD NAME DATA TYPE REMARKS
CITYCODE CHAR(5) Primary Key
CITYNAME CHAR(30)
SIZE INTEGER
AVGTEMP INTEGER
POLLUTIONRATE INTEGER
POPULATION INTEGER
Help her to complete the task by suggesting appropriate SQL commands.
6
31. Write queries (a) to (d) based on the tables EMPLOYEE and DEPARTMENT
given below:
7
(a) SELECT Name, Age FROM VACCINATION_DATA WHERE Dose2 IS NOT NULL
AND Age > 40:
(b) SELECT City, COUNT(*) FROM VACCINATION_DATA GROUP BY City;
(c) SELECT DISTINCT City FROM VACCINATION_DATA;
(d) SELECT MAX (DOSE1), MIN(DOSE2) FROM VACCINATION DATA;
33. Write the output of SQL queries (a) and (b) based on the following two
tables DOCTOR and PATIENT belonging to the same database:
Table:Doctor
DNO DNAME FEES
D1 AMITABH 1500
D2 ANIKET 1000
D3 NIKHIL 1500
D4 ANJANA 1500
TABLE: PATIENT
PNO PNAME ADMDATE DNO
P1 NOOR 2021-12-25 D1
P2 ANNIE 2021-11-20 D2
P3 PRAKASH 2020-12-10 NULL
P4 HARMEET 2019-12-20 D1
(a) SELECT DNAME, PNAME FROM DOCTOR NATURAL JOIN PATIENT;
(b) SELECT PNAME, ADMDATE, FEES FROM PATIENT P, DOCTOR D WHERE D.
DNO = P.DNO AND FEES >1000;
34. Consider the following table PLAYER
Table: PLAYER
PNO NAME SCORE
P1 RISHABH 52
P2 HUSSAIN 45
P3 ARNOLD 23
P4 ARNAV 18
P5 GURSHARAN 42
(a) Identify and write the name of the most appropriate column from the given
table player that can be used as a Primary Key.
(b) Define the term degree in the relational data model. What is the degree of
the given table Player?
8
35. Write SQL queries for (a) to (d) based on the tables PASSENGER and FLIGHT
given below:
Table: Passenger
PNO NAME GENDER FNO
1001 Suresh MALE F101
1002 Anita FEMALE F104
1003 Harjas MALE F102
1004 Nita FEMALE F103
Table: Flight
FNO START END F_DATE FARE
F101 MUMBAI CHENNAI 2021-12-25 4500
F102 MUMBAI BENGALURU 2021-11-20 4000
F103 DELHI CHENNAI 2021-12-10 5500
F104 KOLKATA MUMBAI 2021-12-20 4500
F105 DELHI BENGALURU 2021-01-15 5000
(a) Write a query to change the fare to 6000 of the flight whose FNO is F104.
(b) Write a query to display the total number of MALE and FEMALE
PASSENGERS.
(c) Write a query to display the NAME, corresponding FARE and F_DATE of all
PASSENGERS who have a flight to START from DELHI.
(d) Write a query to delete the records of flights which end at Mumbai.
36. Rohan is learning to work on Relational Database Management System
(RDBMS) application. Help him to perform following tasks:
(a) To open the database named “LIBRARY”.
(b) To display the names of all the tables stored in the opened database.
(c) To display the structure of the table “BOOKS” existing in the already opened
database “LIBRARY”.
9
37. Write SQL queries for (i) to (iv), which are based on the table: STUDENT
given in the question 4(g):
Table: STUDENT
(i) To display the records from table student in alphabetical order as per the
name of the student.
(ii) To display Class, Dob and City whose marks is between 450 and 551.
(iii) To display Name, Class and total number of students who have secured
more than 450 marks, class wise
(iv) To increase marks of all students by 20 whose class is “XII”
10