0% found this document useful (0 votes)
92 views16 pages

DBMS - Worksheet 1 - 5 Marks

The document is a DBMS worksheet for Grade 12 Computer Science, containing various SQL query exercises related to different tables such as Trainer, Course, School, Admin, Mobile Master, and others. It includes tasks like displaying records, updating values, and performing calculations on data. The worksheet aims to enhance students' understanding of SQL commands and database management concepts.

Uploaded by

riyanishu2007
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)
92 views16 pages

DBMS - Worksheet 1 - 5 Marks

The document is a DBMS worksheet for Grade 12 Computer Science, containing various SQL query exercises related to different tables such as Trainer, Course, School, Admin, Mobile Master, and others. It includes tasks like displaying records, updating values, and performing calculations on data. The worksheet aims to enhance students' understanding of SQL commands and database management concepts.

Uploaded by

riyanishu2007
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/ 16

Grade: 12 Computer Science

DBMS
Worksheet - 1
5 Marks
1. Write SQL commands for the following queries (i) to (v) based on the relation Trainer
and Course given below:

(i) Display the Trainer Name, City & Salary in descending order of their Hiredate.
(ii) To display the TNAME and CITY of Trainer who joined the Institute in the month of
December 2001.
(iii) To display TNAME, HIREDATE, CNAME, STARTDATE from tables TRAINER and
COURSE of all those courses whose FEES is less than or equal to 10000.
(iv) To display number of Trainers from each city.
(v) To display the Trainer ID and Name of the trainer who are not belongs to ‘Mumbai’
and ‘DELHI’
2. Write SQL queries for (i) to (v), which are based on the table: SCHOOL and ADMIN
TABLE: SCHOOL TABLE: ADMIN

i) To decrease period by 10% of the teachers of English subject.


ii) To display TEACHERNAME, CODE and DESIGNATION from tables SCHOOL and
ADMIN whose gender is male.
iii) To Display number of teachers in each subject.
iv) To display details of all teachers who have joined the school after 01/01/1999 in
descending order of experience.

DBMS Worksheet – 1 - 5 Marks Page 1


v) Delete all the entries of those teachers whose experience is less than 10 years in
SCHOOL table

3.
Identify the primary key in the table. Write query for the following
ii. Find average salary in the table.
iii. Display number of records for each individual designation.
iv. Display number of records along with sum of salaries for each individual designation
where number of records are more than 1.
v. What is the degree and cardinality of the relation Employee?

4. Write SQL commands for the following queries (i) to (v) on the basis of relation Mobile
Master and Mobile Stock.

DBMS Worksheet – 1 - 5 Marks Page 2


(i) Display the Mobile Company, Name and Price in descending order of their
manufacturing date.
(ii) List the details of mobile whose name starts with “S” or ends with “a”.
(iii) Display the Mobile supplier & quantity of all mobiles except “MB003”.
(iv) List showing the name of mobile company having price between 3000 & 5000.
(v) Display M_Id and sum of Moble quantity in each M_Id.
5. Write SQL commands for i) to v) based on the relations given below

i) To display details of all the items in the Store table in descending order of LastBuy.
ii) To display Itemno and item name of those items from store table whose rate is more
than 15 rupees.
iii) To display the details of those items whose supplier code is 22 or Quantity in store is
more than 110 from the table Store.
iv) To display minimum rate of items for each Supplier individually as per Scode from
the table Store.

DBMS Worksheet – 1 - 5 Marks Page 3


v) To display ItemNo, Item Name and Sname from the tables with their corresponding
matching Scode

6. Write SQL commands for the following queries (i) to (v) based on the relations
TRAINER & COURSE given below:

(i) Display all details of Trainers who are living in city CHENNAI.
(ii) Display the Trainer Name, City & Salary in descending order of their Hiredate.
(iii) Count & Display the number of Trainers in each city.
(iv) Display the Course details which have Fees more than 12000 and name ends with
‘A’. (v) Display the Trainer Name & Course Name from both tables where Course Fees is
less than 10000.

7. Write SQL commands for the queries (i) to (iii) and output for (iv) & (v) based on a
table COMPANY and CUSTOMER .

DBMS Worksheet – 1 - 5 Marks Page 4


(i) To display those company name which are having price less than 30000.
(ii) To display the name of the companies in reverse alphabetical order.
(iii) To increase the price by 1000 for those customer whose name starts with ‘S’
(iv) SELECT PRODUCTNAME,CITY, PRICE FROM COMPANY,CUSTOMER WHERE
COMPANY.CID=CUSTOMER.CID AND PRODUCTNAME=”MOBILE”;
(v) SELECT AVG(QTY) FROM CUSTOMER WHERE NAME LIKE “%r%;

8. Write SQL Commands for the following queries based on the relations PRODUCT and
CLIENT given below.

(i) To display the ClientName and City of all Mumbai- and Delhi-based clients in Client
table.
(ii) Increase the price of all the products in Product table by 10%.
(iii) To display the ProductName, Manufacturer, ExpiryDate of all the products that
expired on or before ‘2010-12-31’.

DBMS Worksheet – 1 - 5 Marks Page 5


(iv) To display C_ID, ClientName, City of all the clients (including the ones that have not
purchased a product) and their corresponding ProductName sold.
(v) To display productName, Manufacturer and ClientName of Mumbai City.

9. Consider the following tables Sender and Recipient. Write SQL commands for the
statements (a) to (c) and give the outputs for SQL queries (d) to (e).

a. To display the RecIC, Sendername, SenderAddress, RecName, RecAddress for every


Recipient
b. To display Recipient details in ascending order of RecName
c. To display number of Recipients from each city
d. To display the details of senders whose sender city is ‘mumbai’
e. To change the name of recipient whose recid is ’Ko05’ to’ S Rathore’.

DBMS Worksheet – 1 - 5 Marks Page 6


10. Write SQL commands for (i) to (v) on the basis of relations given below:
TABLE: BOOK

TABLE; ISSUED

(i) To show the books of FIRST PUBL. Publishers written by P. Purohit.


(ii) To display cost of all the books published for EPB.
(iii) Depreciate the price of all books of EPB publishers by 5%.
(iv) To display the BOOK_NAME and price of the books, more than 5 copies of which
have been issued.
(v) To show total cost of books of each type.

11. Consider the tables given below.


TABLE: STOCK

TABLE: DEALER

DBMS Worksheet – 1 - 5 Marks Page 7


(i) To display all the information about items containing the word “pen” in the field
Itname in the table STOCK.
(ii) List all the itname sold by Vikash Stationers.
(iii) List all the Itname and StkDate in ascending order of StkDate.
(iv) List all the Itname, Qty and Dname for all the items for the items quantity more than
40.
(v) List all the details of the items for which UnitPrc is more than 10 and <= 50.
12. 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.

13. 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
DBMS Worksheet – 1 - 5 Marks Page 8
MNAME - character of size 20
PRICE - numeric
UNITS - numeric
EXPIRY - date
Table : PHARMA

(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

DBMS Worksheet – 1 - 5 Marks Page 9


14. 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.
15. i) What do you mean by a Primary key in RDBMS ?
ii) Complete the following database connectivity program by writing the missing
statements and performing the given query
import ------------------- as mysql # statement 1
con=mysql. ---------(host=’localhost’,user=’root’,passwd=’123’ ,
database=’student’) # statement 2
cursor=con.cursor( )
cursor.execute(--------------------------------) # statement 3
data=cursor. ----------------------------------- # statement 4
for rec in data:
print(rec)

DBMS Worksheet – 1 - 5 Marks Page 10


con.close( )
a) Complete the statement 1 by writing the name of package need to be imported for
database connectivity .
b) Complete the statement 2 by writing the name of method require to create connection
between Python and mysql.
c) Complete the statement 3 by writing the query to display those students record whose
mark is between 50 and 90 from table “student”
d) Complete the statement 4 to retrieve all records from the result set.
OR
i) What is the difference between UNIQUE and PRIMARY KEY constraints ?
ii) Maya has created a table named BOOK in MYSQL database, LIBRARY
BNO(Book number )- integer
B_name(Name of the book) - string
Price (Price of one book) –integer
Note the following to establish connectivity between Python and
MySQL: Username – root, Password – writer,Host – localhost.
Maya, now wants to display the records of books whose price is more than 250. Help
Maya to write the program in Python

16. (i) What is the difference between a Candidate Key and an Alternate Key.
(ii) Virat has created a table named TRAVELS in MySQL:
Tour_ID – string
Destination – String
Geo_Cond– String
Distance – integer (In KM)
Note the following to establish connectivity between Python and MYSQL:
Username is root
Password is bharat
The table TRAVELS exists in a MYSQL database named TOUR.
The details Tour_ID, Destination, Geo_Cond and Distance are to be accepted
from the user.
Virat wants to display All Records of TRAVELS relation whose Geographical conditionis
hilly area and distance less than 1000 KM. Help Virat to write program in python.
OR

DBMS Worksheet – 1 - 5 Marks Page 11


(i) Write one point of difference between PRIMARY KEY and UNIQUE KEY in SQL.
(ii) Aarya has created a table named Emp in MySQL:
EmpNo – integer
EmpName – string
Age– integer
Salary – integer
Note the following to establish connectivity between Python and MYSQL:
Username - root
Password - tiger
Host - localhost
The Emp table exists in a MYSQL database named company.
The details of Emp table (EmpNo, EmpName, Age and Salary)
Aarya wants to display All Records of Emp relation whose age is greater than 55. Help
Aarya to write program in python.

17. (i) How many candidate key and primary key a table can have in a Database?
(ii) Manish wants to write a program in Python to create the following table
named “EMP” in MYSQL database, ORGANISATION:
Eno (Employee No )- integer , Ename (Employee Name) - string
Edept (Employee Department)-string, Sal (salary)-integer
Note the following to establish connectivity between Python and MySQL:
Username – root , Password – admin , Host - localhost
The values of fields eno, ename, edept and Sal has to be accepted from the
user. Help Manish to write the program in Python to insert record in the above
table..
OR
(i) Differentiate between degree & cardinality key in RDBMS?
(iii) Vihaan wants to write a program in Python to create the following table
named “EMP” in MYSQL database, ORGANISATION:
Eno (Employee No )- integer , Ename (Employee Name) - string
Edept (Employee Department)-string, Sal (salary)-integer
Note the following to establish connectivity between Python and MySQL:
Username – root , Password – admin , Host - localhost
Help Vihaan to write the program in Python to Alter the above table with new

DBMS Worksheet – 1 - 5 Marks Page 12


column named Bonus (int).
18. Consider the following table Cab:

(i) Which column qualifies to be the primary key?


(ii) Write a command to display the fields of the table along with their types and sizes.
(iii) Write statements to :
(a) Add a new column Driver varchar(30)
(b) Change data type of Rate column to float(6,1).
(Option for part (iii) only)
(a) To display the cab type whose rate is more than 25.
(b) To display cab id and Number of passengers for cab sedan.
19. Consider the following table

i) What would be the width of Dateofadm field?


(ii) Write commands to remove the records of “Cardiology” department.
(iii) Write statements to :
(a) Display a report showing Name, charges and discount (15%) for all patients.
(b) Display names of female patients .
OR (option for part (iii) only)
(a) Which function will find the total charges of all patients?
(b) Name the constraint that will restrict duplicate values in Name column.
20. Consider the following table ORDERS :

DBMS Worksheet – 1 - 5 Marks Page 13


(i) Write a statement to create the above table.
(ii) Write a command to change the width of Customer column to varchar(30)
(iii) Write statements to :
(a) Display the field names, their type , size and constraints .
(b) Display details of orders where orderprice is in the range 500 to 1500
OR (Option for part iii only)
(a) Write a command to increase orderprice of all orders by 15%.
(b) Name the constraint that will restrict both NULL and DUPLICATE values in the O_Id
field.
20. Consider the following table FLIGHTS :

(i) The command to create the table was written as :


Create table FLIGHTS( FL_NO integer, STARTING char(20), ENDING char(30),
NO_FLIGHT integer, NO_STOPS integer);
What is wrong with command ?
(ii) What is the cardinality of the table ?
(iii) Which functions will be used to :
(a) Display total number of flights .
(b) Display number of flights whose FL_NO starts with “IC”
(option for part (iii) only)

DBMS Worksheet – 1 - 5 Marks Page 14


Write function names to :
(a) Show the average Number of stops.
(b) Show the maximum number of stops.
21. i) Give one point of difference between an equi-join and a natural join.
ii) Write the user defined function display ( ) in python to execute the query that fetches
records of the employees coming from the city ‘Delhi’.
E_code - string
E_name - String
Sal = Integer
City - string
Note the following to establish connectivity between Python and MySQL:
❖ Username is root
❖ Password is root
❖ The table exists in a MySQL database named emp.
❖ The details (E_code, E_name, Sal, City) are the attributes of the table.
22. i) Are count (*) and count()the same functions? Why/why not?
ii) The code given below inserts the following record in the table Emp:
EmpNo – integer
EName – string
Desig – string
Salary – integer
Note the following to establish connectivity between Python and MYSQL:
Username is admin
Password is 22admin66
The table exists in a MYSQL database named company.
The details (EmpNo, EName, Desig and Salary) are to be accepted from the user. Write
the program in Python to meet the above need.
23. i. Define the term Degree with respect to RDBMS. Give one example to support your
answer
ii. Kavyawants to write a program in Python to insert the following recordin the table
named Inventory in MYSQL database,
WAREHOUSE:
Inv_No(Inventory Number )- integer
Inv_name(Name) – string

DBMS Worksheet – 1 - 5 Marks Page 15


Inv_Entry(Date )
Inv_price – Decimal
Note the following to establish connectivity between Python andMySQL:
Username - root
Password - 12345
Host - localhost
The values of fields Inv_No, Inv_name, Inv_Entryand Inv_price has to be accepted
fromthe user. Help Kavyato write the program in Python.

DBMS Worksheet – 1 - 5 Marks Page 16

You might also like