DBMS - Worksheet 1 - 5 Marks
DBMS - Worksheet 1 - 5 Marks
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
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.
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.
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 .
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’.
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).
TABLE; ISSUED
TABLE: DEALER
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
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
(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)
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
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