0% found this document useful (0 votes)
35 views

document_1000000562

Uploaded by

vishwaaj10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

document_1000000562

Uploaded by

vishwaaj10
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

SQL REVISION QUESTIONS

1. Anmol maintains that database of Medicines for his pharmacy using SQL to store the data. The structure of
the table PHARMA for the purpose is as follows :
Name of the table – PHARMA. The attributes of PHARMA are as follows :
MID – numeric, MNAME - character of size 20, PRICE – numeric, UNITS – numeric, EXPIRY – date

(a) Write the degree and cardinality of the table PHARMA.


(b) Identify the attribute best suitable to be declared as a primary key.
(c) Anmol has received a new medicine to be added into his stock, but for which he does not know the
number of UNITS. So, he decides to add the medicine without its value for UNITS. The rest of the values are
as follows:

Write the SQL command which Anmol should execute to perform the required task.
(d) Anmol wants to change the name of the attribute UNITS to QUANTITY in the table PHARMA. Which of the
following commands will he use for the purpose?
(i) UPDATE (ii) DROP TABLE (iii) CREATE TABLE (iv) ALTER TABLE
(e) Now Anmol wants to increase the PRICE of all medicines by 5. Which of the following commands will he
use for the purpose?
(i) UPDATE SET (ii) INCREASE BY (iii) ALTER TABLE (iv) INSERT INTO
2. Write the outputs of the SQL queries (i) to (iii) based on the relations CUSTOMER and TRANSACTION given
below :

(i) SELECT MAX(BALANCE), MIN(BALANCE)FROM CUSTOMER WHERE GENDER = 'M';


(ii) SELECT SUM(AMOUNT), TYPE FROM TRANSACTION GROUP BY TYPE;
(iii) SELECT NAME, TDATE, AMOUNT FROM CUSTOMER C, TRANSACTION T WHERE C.ACNO = T.ACNO AND
TYPE = 'CREDIT';

3. Write SQL statements for the following queries (i) to (v) based on the relations CUSTOMER and
TRANSACTION given below :
(a) To display all information about the CUSTOMERS whose NAME starts with 'A'.
(b) To display the NAME and BALANCE of Female CUSTOMERS (with GENDER as 'F') whose TRANSACTION
Date (TDATE) is in the year 2019.
(c) To display the total number of CUSTOMERS for each GENDER.
(d) To display the CUSTOMER NAME and BALANCE in ascending order of GENDER.

(e) To display CUSTOMER NAME and their respective INTEREST for all CUSTOMERs where INTEREST is
calculated as 8% of BALANCE.
4. 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

(a) Identify the attribute best suitable to be declared as a primary key


(b) Write the degree and cardinality of the table STORE.
(c) Insert the following data into the attributes ItemNo, ItemName and SCode respectively in the given table
STORE. ItemNo = 2010, ItemName = “Note Book” and Scode = 25
(d) Abhay want to remove the table STORE from the database MyStore.

Which command will he use from the following:


a) DELETE FROM store; b) DROP TABLE store;
c) DROP DATABASE mystore; d) DELETE store FROM mystore;
(e) Now Abhay wants to display the structure of the table STORE, i.e, name of the attributes and their
respective data types that he has used in the table. Write the query to display the same.
5. Write SQL commands for the following queries (i) to (v) based on the relations Teacher and Posting given
below:

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.
vi. To display name, department and place of posting of all teachers.
6. Consider the table, MOVIEDETAILS given below:

Table: MOVIEDETAILS

(a) Identify the degree and cardinality of the table.


(b) Which field should be made the primary key? Justify your answer. OR
Identify the candidate key(s) from the table MOVIEDETAILS.
(c) Consider the table SCHEDULE given below:
Table: SCHEDULE

Which field will be considered as the foreign key if the tables MOVIEDETAILS and SCHEDULE are related in a
database?

7. 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.
8. Categorize following commands into DDL and DML commands?
INSERT INTO, DROP TABLE, ALTER TABLE, UPDATE...SET

9. Write queries (a) to (d) based on the tables EMPLOYEE and DEPARTMENT given below:
(a) To display the average salary of all employees, department wise.
(b) To display name and respective department name of each employee whose salary is more than 50000.
(c) To display the names of employees whose salary is not known, in alphabetical order.

(d) To display DEPTID from the table EMPLOYEE without repetition.

10. Write the output of SQL queries (a) and (b) based on the following two tables DOCTOR and PATIENT
belonging to the same database

11. A SQL table ITEMS contains the following columns: INO, INAME, QUANTITY, PRICE, DISCOUNT
Write the SQL command to remove the column DISCOUNT from the table.
12. Write SQL queries for (a) to (d) based on the tables PASSENGER and FLIGHY given below.

13. Write the output of the SQL queries (a) to (d) based on the table VACCINATION_DATA given below:
14. Write the output of the SQL queries (a) and (b) based on the following two tables FLIGHT and PASSENGER
belonging to the same database :

(a) SELECT NAME, DEPART FROM FLIGHT NATURAL JOIN PASSENGER ;


(b) SELECT NAME, FARE FROM PASSENGER P, FLIGHT F WHERE F.FNO = P.FNO AND F.DEPART = 'MUMBAI' ;
15. Consider the following table BATSMEN :

Table : BATSMEN

(i) Identify and write the name of the Candidate Keys in the given table BATSMEN.
(ii) How many tuples are there in the given table BATSMEN ?
16. Write SQL queries for (a) to (d) based on the tables CUSTOMER and TRANSACT given below :

(a) Write the SQL statements to delete the records from table TRANSACT whose amount is less than 1000.
(b) Write a query to display the total AMOUNT of all DEBITs and all CREDITs.
(c) Write a query to display the NAME and corresponding AMOUNT of all CUSTOMERs who made a
transaction type (TTYPE) of CREDIT.
(d) Write the SQL statement to change the Phone number of customer whose CNO is 1002 to 9988117700 in
the table CUSTOMER.
17. (a) Write the outputs of the SQL queries (i) to (iv) based on the relations Teacher and Placement given
below:
Table : Teacher

(i) SELECT Department, avg(salary) FROM Teacher GROUP BY Department;


(ii) SELECT MAX(Date_of_Join),MIN(Date_of_Join) FROM Teacher;
(iii) SELECT Name, Salary, T.Department, Place FROM Teacher T, Placement P WHERE T.Department =
P.Department AND Salary>20000;
(iv) SELECT Name, Place FROM Teacher T, Placement P WHERE Gender =’F’ AND
T.Department=P.Department;
18.

19 .
20.

21.
22.

23. Consider the table CLUB given below and write the output of the SQL queries that follow.

i) SELECT COUNT(DISTINCT SPORTS) FROM CLUB;


(ii) SELECT CNAME, SPORTS FROM CLUB WHERE DOAPP<"2006-04-30"
AND CNAME LIKE "%NA";
(iii) SELECT CNAME, AGE, PAY FROM CLUB WHERE GENDER = "MALE"
AND PAY BETWEEN 1000 AND 1200;
24. Consider the table Personal given below:
Table: Personal

Based on the given table, write SQL queries for the following:
(i) Increase the salary by 5% of personals whose allowance is known.
(ii) Display Name and Total Salary (sum of Salary and Allowance) of all personals. The
column heading ‘Total Salary’ should also be displayed.
(iii) Delete the record of personals who have salary greater than 25000
25. Consider the tables PRODUCT and BRAND given below:
Table: PRODUCT

Write SQL queries for the following:


(i) Display product name and brand name from the tables PRODUCT and BRAND.
(ii) Display the structure of the table PRODUCT.
(iii) Display the average rating of Medimix and Dove brands
(iv) Display the name, price, and rating of products in descending order of rating

You might also like