DBMS - Worksheet 1 - 3 Marks
DBMS - Worksheet 1 - 3 Marks
DBMS
Worksheet - 1
3 Marks
1. Write the output of the queries (i) to (vi) based on the table given below:
(i) Select BRAND_NAME, FLAVOUR from CHIPS where PRICE <> 10;
(ii) Select * from CHIPS where FLAVOUR=”TOMATO” and PRICE > 20;
(iii) Select BRAND_NAME from CHIPS where price > 15 and QUANTITY < 15;
(iv) Select count( distinct (BRAND_NAME)) from CHIPS;
(v) Select price , price *1.5 from CHIPS where FLAVOUR = “PUDINA”;
(vi) Select distinct (BRAND_NAME) from CHIPS order by BRAND_NAME desc;
2.(A) Consider the following tables BOOKS and ISSUED in a database named “LIBRARY”.
WriteSQL commands for the statements (i) to (iv).
(i) Display book name and author name and price of computer type books.
(ii) To increase the price of all history books by Rs 50.
(iii) Show the details of all books in ascending order of their prices.
(iv) To display book id, book name and quantity issued for all books which have been
issued.
(B)Write the command to view all tables in a database.
4. Write the outputs of the SQL queries (i) to (iii) based on the relations Teacher and
Posting given below:
12. a. Consider the following tables ACTIVITY and COACH.Write SQL commands for the
statements (i) to (iv) and give the The outputs for the SQL queries (v) to (viii)
Table: Activity
(i) To display the name of all activities with their Acodes in descending order.
(ii) To display sum of PrizeMoney for each of the number of participants groupings (as
shown in column ParticipantsNum 10,12,16)
(iii) To display the coach’s name and ACodes in ascending order of ACode from the table
COACH.
(iv) To display the content of the Activity table whose ScheduleDate is earlier than
01/01/2004 in ascending order of ParticipantsNum.
What is the degree and cardinality of table Employee, if it contains only the given data?
Which field fields is/are the most suitable to be the Primary key if the data shown above
is only the partial data?
(b) Write the output of the queries (i) to (iv) based on the table Employee:
(i) select name, project from employee order by project;
(ii) select name, salary from employee where doj like'2015%';
(iii)select name, salary from employee where salary between 100000 and 200000;
(iv) select min(doj), max(dob) from employee;
16. (a) Write the outputs of the SQL queries (i) to (iv) based on the relations Projects and
Employee given below:
i.SELECT Designation COUNT (*) FROM Admin GROUP BY Designation HAVING COUNT
(*) <2:
ii.SELECT max (EXPERIENCE) FROM SCHOOL;
iii. .SELECT TEACHER FROM SCHOOL WHERE EXPERIENCE >12 ORDER BY
TEACHER;
iv.SELECT COUNT (*), GENDER FROM ADMIN GROUP BY GENDER;
18. (a)Sonal needs to display name of teachers, who have “0” as the third character in
their name. She wrote the following query.
SELECT NAME FROM TEACHER WHERE NAME = “$$0?”;
But the query is’nt producing the result. Identify the problem.
(b)Write output for (i) & (iv) based on table COMPANY and CUSTOMER
22. (a) Write the outputs of the SQL queries (i) to (iv) based on the relations SCHOOL
and ADMIN given below:
Table: School Table: Admin
The Following program code is used to increase the salary of Trainer SUNAINA by 2000.
Note the following to establish connectivity between Python and MYSQL:
Username is root
Password is system
The table exists in a MYSQL database named Admin.
Write the following missing statements to complete the code:
Statement 1 – to form the cursor object
Statement 2 – to execute the command that inserts the record in the table Student.
Statement 3- to add the record permanently in the database
import mysql.connector as mydb
mycon = mydb.connect (host = “localhost”, user = “root”, passwd = “system”, database =
“Admin”)
cursor = _______________ #Statement 1
sql = “UPDATE TRAINER SET SALARY = SALARY + 2000 WHERE TNAME = ‘SUNAINA’”
cursor. _______________ #Statement 2
_______________ #Statement 3
mycon.close( )