Professional Documents
Culture Documents
Worksheet-1
(b) A table ‘Aadhar” has 5 columns and 3 rows in it. After adding 6 rows and deleting 2
rows. What will be the degree and cardinality of this table.
Table : KID
(i) Write command to display item details whose name start from ‘B’.
(ii) Write command to arrange the record in descending order on the basis of Unit Price.
(iii) Write command to display the item name whose price is maximum.
(iv) Display the details of items whose price between ranges 600 to 800.
(v) To display the list of items whose discount is more than 10%.
(vi) To display name of item and their date of purchase that were purchased after 31 st Dec
2016.
(vii) To increase the unit price of each item by 10% of their unit price.
(viii) To display the details of those item whose unit price is more than 5000.
Q5. (a)Anil has created the following table with name ‘Employee’.
ColumnName Constraint
EmpID Primary Key
DOJ
Ename Not Null
Basic
One of the rows inserted is as follows :
EmpID DOJ Ename Basic
A1 2016-02-12 Pradeep 20000
What are the data type of columns EmpiD and DOJ?
EmpID DOJ Ename Basic
A2 2016-08-09 NULL Rajesh Mishra
Will he be able to successfully insert it ? Give reason.
(b) Write the output of following SQL quries:
(i) Select Dayofyear(‘2016-01-30’);
(ii) Select Mid(‘Welcome to Kanpur’, 2,4);
(iii) Select Round (56.484,2);
(iv) Select Instr(‘How Computer Work’, ‘mp’);
(c)Consider the following table GYM with details about fitness products being
sold in the store. Write command of SQL for (i) to (viii) and output for (ix) to (x).
Table: GYM
PCOD PNAME PRICE MANUFACTURER
E
P101 Treadmill 21000 Coscore
P102 Bike 20000 Aone
P103 Cross Trainer 14000 Reliable
P104 Multi Gym 34000 Coscore
P105 Massage chair 5500 Regrosene
P106 Belly Vibrator Belt 6500 Ambaway
(i) To display the details of all the producut.
(ii)To display the names of all products whose first character is ,'M'
(iii) To display the name of all manufacturer without duplicate.
(iv) Toupdate price of all product by Rs 200.
(v) To add a new column named "Discount" in this table.
(vi) To arrange the record on the column Price in descending order.
(vii) to display the structure of this table.
(viii) To add a new record with your own data.
(ix)SELECT * FROM GYM WHERE MANUFACTURER NAME
LIKE“%m%”;
(x)SELECT COUNT (DISTINCT (MANUFACTURER)) FROM GYM
Worksheet-3
Q1. (a) Distinguish between Single Row and Aggregate function of MySQL. Write one
example
of each.
(b) Consider the table Teacher given below. Write commands in SQL for (i) to (viii) and
output for (ix) to (x)
TEACHER
Id Name Department Hiredate Category Gender Salary
1 John SocialStudies 1994-03-17 TGT F 25000
2 Anil Art 1990-02-12 PRT M 20000
3 Bhavika English 1980-05-16 PGT F 30000
4 James English 1989-10-16 TGT M 25000
5 Jaspreet Hindi 1990-08-01 PRT F 22000
6 Disha Math 1980-03-17 PRT F 21000
7 Siddarth Science 1994-09-02 TGT M 27000
8 Sonali Math 1980-11-17 TGT F 24500
(i)To display the structure of table.
(ii) To add a new column games of varchar data type.
(iii) To drop the column games we have added.
(iv) To display all information about teachers of TGT category.
(v) To list the names of female teachers of “English” department.
(vi) To list names, departments and date of hiring of all the teachers in ascending order of
date of joining
(vii) To count the number of teachers in English department.
(viii) SELECT DISTINCT(category) FROM teacher;
(ix) SELECT COUNT(*) FROM TEACHER WHERE Category = "PGT";
(x) SELECT AVG(Salary) FROM TEACHER group by Gender;
(c) A Table Doctor contain 3 rows and 5 columns in it. Write the degree and cardinality
of
this table.
Worksheet-4
Q1. (a) Write the difference between DROP TABLE and DELETE command of MySQL.
(b) Name a function of MySQL used to give the first occurrence of a string2 in string1.
(c) Consider the table RESULT given below. Write commands in MySql for (i) to (iv)
and output for (v) to (vii)
Table :RESULTSHEET
Worksheet-5
Q1. (a) A table has 5 column while entering data, value of column number 3 is not
available. Anil entered following command. What’s wrong in it? Write correct query
after removing error.
(C) Consider the table Supplier given below. Write command in MySql for (i) to (vii) and
output for (viii) to (x) .
Table : Supplier
3) Write the SQL commands for the i) to iv) and write the output v to vii
basis of table STUDENT.
TABLE: STUDENT
Stipen AvgMar
No Name Stream Grade Class
d k
Kamles
1 400.00 Medical 78.0 B 12B
h
2 Praveen 450.00 Commerce 88.2 A 11C
3 Manoj 300.00 Commerce 67.6 C 12C
4 Laxmi 350.00 Humanities 77.1 B 12C
5 Suja 350.0 Nonmedical 78.6 B 11A
6 Basima 500.00 Humanities 89.4 A 12B
7 Soju 400.00 Nonmedical 88.4 A 11A
8 Deepa 250.00 Nonmedical 75.5 B 12A
9 Shushil 450.00 Humanities 92.4 A 12A
10 Baba 300.00 Commerce 92.5 A 12C
(i) Select all the Commerce stream students.
(ii) List the names of those students who are in class 12 sorted by Stipend.
(iii) List the Name, Grade, Class of students sorted by AvgMark in descending order.
(iv) Display the Name, Stipend, Stream and amount of stipend received in a year
assuming that the Stipend is paid every month.
WORKSHEET 7
3 Consider the table GARMENTgiven below, write command in SQL for (a) to (d) and output for (e) to
(h).
Table : GARMENT
WORKSHEET 8
3) Consider the table given below, write command in MySQL for (i) to (iv) and output for (v) to (viii).
Table :STUDENT
i. To display the name and stream of all students who are in class 12.
ii. To display the different Streams available for students.
iii. To display name, avgmarks and grade in descending order of grade.
iv. To display names of those students whose grade and section are same.
v. SELECT STIPEND+500 FROM STUDENT WHERE STREAM LIKE ‘%a%’;
vi. SELECT COUNT(*) FROM STUDENT WHERE GRADE= ‘C’ AND STIPEND>=800;
vii. SELECT CLASSSEC FROM STUDENT WHERE AVGMARKS>68 && STREAM= ‘Medical’;
viii. SELECT MAX(STIPEND) FROM STUDENT ;
WORK SHEET 9
3 Consider the table EXAM given below. Write command in MySQL for (i) to (vi) and
output (v) to (viii).
6
(i) To list the names of those students who have obtained Division First in the ascending order of
Name.
(ii) To display a report listing Name, Subject and Annual stipend received assuming that the stipend
column has monthly stipend.
(iii) To count the number of students, who have either Accounts or informatics as subject.
(iv) Insert a new row. 7,”Mohan”,500,”English”,73,”Second”
(v) Select AVG(Stipend) from Exam where Division=”Third”;
(vi) Select count(Distinct Subject) From Exam;
(vii) Select Min(Average) from Exam where Subject=”English”;
(viii) Select Sum(Average) from Exam where Division=”First”;
WORKSHEET 10
1) Differentiate between DROP TABLE and DELETE commands in Mysql. Explain each with example.
3 Consider the table TEACHER given below. Write commands in SQL for (i) to (iv) and output for (v) to (viii)
Join Queries
Worksheet- 1
6(a) Write an SQL query to create the table “BookDetails“ with the following structure- 2
(b) In a database there are two tables ‘Patient’ and ‘Doctors’ are shown below- 2
Table: Patient
Name Patient_No Date_Adm Doctor_No
Aneesh P104 2009-05-15 502
Shraddha K P202 2010-01-11 165
Reshmi Nair P754 2007-12-31 325
Sunitha P P612 2010-04-22 165
Table: Doctor
Doctor_No Doctor_Name Specialty
122 Dr. Sabir Khan Urology
165 Dr.R. K. Tiwari Neurology
325 Dr. S.L. Sargaiya Surgery
502 Dr. Priya Nephrology
530 Dr. Kamal Kishore Dentist
i) Name the columns which can be made ‘Primary Key’ in both the tables.
ii) What will be the cardinality of Cartesian product of both the tables?
Table : DEALERS
Dcode Dname Location
101 Vikash Stationers Lanka Kanpur
102 Bharat Drawing Emporium Luxa Lucknow
103 Banaras Books Corporation Bansphatak Varanasi
With reference to these tables, write commands in SQL for (i) and (ii) and output for (iii)
below-
(i) To display the amount that has been spent to purchase Office file & Sharpener
camlin.
(ii) To display all the items of Vikash Stationers.
(iii) SELECT DCODE,COUNT(QTY),AVG(UNITPR) FROM STOCK GROUP BY DCODE;
Worksheet-2
6(a) What is Primary Key and Candidate Key? Discuss with example. 2
(b) What is the difference between Drop and Delete Command? Discuss with example. 2
( c) Consider the following two tables stored in a database 6
The "Persons" table:
Worksheet-3
6(a) Write SQL to Create the following table BANK with specified constraints 2
(b) Can we change the column name using Alter table command? Change the data type of 2
Budget column of above mentioned BANK Table to Numeric(10,2) and add default value to
1000000.
( c) Consider the following tables FURNITURE and TYPE. Write SQL commands for the
statements (i) to (iv) and give outputs for SQL queries (v) to (viii) 6
TABLE : FURNITURE
FID FNAME TYPENO CHARGES ARRIVAL
1 WHITE LOTUS F01 30000 21-11-2012
2 PINK FEATHER F02 7500 16-11-2012
3 DOLPHIN F02 9500 14-11-2012
4 DECENT F01 25000 5-09-2011
5 COMFORT F03 15000 12-10-2011
6 ROYAL F02 6500 3-05-2011
7 ECONO F03 9500 1-06-2012
TABLE : TYPE
TYPENO TYPENAME DISCOUNT
F01 DOUBLE BED 30
F02 BABY COT 20
F03 OFFICE TABLE 10
(i) To display all the details of furniture whose CHARGES is more than 10000
(ii) To increase the CHARGES of furniture by 5% of existing charge for furniture
arrived after 1-09-2011
(iii) To display the details of furniture of type OFFICE TABLE
(iv) To insert a new row with the following data in FURNITURE table
8, “Velvet Touch”, “F01” , 25000, “25-03-2011”
(v) Select TYPENO, count(* ) from FURNITURE group by TYPENO;
(vi) Select FNAME, CHARGES from FURNITURE where FNAME like “ %T “;
Worksheet-4
(b) Write Mysql command to create the Table Employee with the given constraints. 2
Table: EMPLOYEE
Column EmpID EmpName EmpAdd EmpPhone EmpSal DeptID
Name
Key type Primary Foreign
6(a) At the time of creation of table X, the data base administrator specified Y as the 2
Primary key. Later on he realized that instead of Y, the combination of column P and
Q should have been the primary key of the table. Based on this scenario, answer the
following questions:
a. Is it possible to keep Y as well as the combination of P and Q as the primary key?
b. What statement(s) should be entered to change the primary key as per the
requirement.
(b) What is the difference between Drop and Delete Command? 2
( c) Consider the following tables SCHOOL and ADMIN. Write SQL commands for the 6
statements (i) to (iv) and give outputs for SQL queries (v) to (viii).
SCHOOL
CODE TEACHERNAME SUBJECT DOJ PERIODS EXPERIENCE
1001 SAJI ENGLISH 12/03/2009 24 10
1009 RUBI PHYSICS 03/09/2008 26 12
1203 JAYANTHI ENGLISH 09/04/2000 27 5
1045 AMIT SINHA MATHS 24/08/2000 24 15
1123 ASHOK RAO PHYSICS 16/07/1999 28 3
1167 HARI KRISHNAN CHEMISTRY 19/10/2017 27 5
1215 AMIT PANDEY PHYSICS 11/05/2016 22 16
ADMIN
CODE GENDER DESIGNATION
1001 MALE VICE PRINCIPAL
1009 FEMALE COORDINATOR
1203 FEMALE COORDINATOR
1045 MALE HOD
1123 MALE SENIOR TEACHER
1167 MALE SENIOR TEACHER
1215 MALE HOD
i) To display TEACHERNAME, PERIODS of all teachers whose periods less than 25.
ii) To display TEACHERNAME, CODE and DESIGNATION from tables SCHOOL and ADMIN
whose gender is male.
iii) To display thenumber of teachers in each subject.
iv) To display CODE, TEACHERNAME and SUBJECT of all teachers who have joined the
school after 01/01/2008.
v) SELECT MAX (EXPERIENCE), SUBJECT FROM SCHOOL GROUP BY SUBJECT;
vi) SELECT TEACHERNAME, GENDER FROM SCHOOL, ADMIN WHERE DESIGNATION =
‘COORDINATOR’ AND SCHOOL.CODE=ADMIN.CODE;
vii) SELECT DESIGNATION, COUNT (*) FROM ADMIN GROUP BY DESIGNATION HAVING
COUNT (*) <2;
Worksheet – 6
Time : 30 min M.M.10
Write answers at the back side of the sheet
1. Write SQL query to create a table ‘Song’ with the following structure :
2
Field Type Constraint
Songid Integer Primary key
Title Varchar (50) Not Null
Duration Integer Check >=3 and <=8
ReleaseDate Date
Language Varchar(20) Default 5
2. In a database there are two tables ‘BRANDtab’ and ‘ITEM’ as shown below: 1+1
3. Write SELECT Statement based on the table BRANDtab and ITEM given In ques 3. 2X3=06
I. Write Statement to display ICODE, INAME, BRAND and price from table BRANDtab and
ITEM.
II. Write Statement to display ICODE, INAME, BRAND and price from table BRANDtab and
ITEM of items with price more than 50000.
III. Write Statement to display ICODE, INAME, BRAND and price from table BRANDtab and
ITEM of items with INAME like “%R”.
Worksheet – 7
Time : 30 min M.M.10
Write answers at the back side of the sheet
1. Create Table EMPLOYEE as per the structure given below : 2
Table : EMPLOYEE :
Column Name Datatype Size Constraint
empno integer Primary Key
ename char 20 Not Null
job char 10 Not Null
mgr integer
hiredate date
sal decimal 10,2 >2000
comm integer
deptno integer Foreign Key
gender char 1 default ‘M’
2. Consider the following tables GAMES & PLAYER and Write the answers of the questions that follow : 2
Table: GAMES
GCode GameName Number PrizeMoney ScheduleDate
101 Carom Board 2 5000 2019-01-23
102 Badminton 2 12000 2018-12-12
103 Table Tennis 4 8000 2020-02-14
105 Chess 2 9000 2018-01-01
108 Lawn Tennis 4 25000 2019-03-19
Table: PLAYER
PCode Name Gcode
1 Nabi Ahmad 101
2 Ravi Sahai 108
3 Jatin 103
4 Nazneen 103
5 Virat 102
6 Yuvraj 101
7 Sania 105
8 Geeta 108
I. Name the Primary keys in both the tables and Foreign Key in PLAYER Table.
II. In the table ‘PLAYER’, values in GCODE are repeated in the column “Gcode”. Is there any
discrepancy? Give reason.
3. Consider the following tables GAMES and PLAYER given in question 2 and Write SQL commands for the
statements given in Q (1) and (2) and give outputs for SQL query (3). 6
I. To display the content player name, gamename of those player whose game is scheduled in the year
2019.
II. To display sum of PrizeMoney for each of the Number of participation groupings (as shown in column
Number 3 table Games).
III. SELECT NAME,GAMENAME FROM GAMES G,PLAYER P WHERE P.GCODE=G.GCODE AND
NAME LIKE “%A_”;
Worksheet – 8
Time : 30 min M.M.10
Write answers at the back side of the sheet.
1. Consider the structure of table campus given below and write statement to CREATE this table. 2
Table : Campus
Table : Party
Party Id Descrip tio n Co st P er P erso n
P101 Birthday 400
P102 Wedding 700
P103 Farewell 350
P104 Engagement 450
Table : Client
ClientId ClientName Ad dr e s s Pho ne NoOfGuests PartyId
3. Write commands in SQL for (i) & (ii) and Output for (iii) : 6
i. To display Client Name, Party Description and NoOfGuests * CostPerPerson as Totalcost for those
clients whose total cost is more than 200000.
ii. To display ClientId, C l i e n t Name, PartyId and Description of clients for only those parties that
have less than 100 NoOfGuests.
iii. SELECT CLIENTNAME,PHONE,DESCRIPTION FROM PARTY P, CLIENT C
WHERE C.PARTYID=P.PARTYID AND CLIENTNAME NOT LIKE “%A”;
Worksheet – 9
Time : 30 min M.M.10
Write answers at the back side of the sheet.
2. Write commands in SQL for (4) to (8) and Output for (9) and (10) based on the table
DEPT and EMPLOYEE given below:
2
Table : EMP
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
7369 SMITH CLERK 7902 17-DEC-80 800 20
7499 ALLEN SALESMAN 7698 20-FEB-81 1600 300 30
7521 WARD SALESMAN 7698 22-FEB-81 1250 500 30
7566 JONES MANAGER 7839 02-APR-81 2975 20
7654 MARTIN SALESMAN 7698 28-SEP-81 1250 1400 30
7698 BLAKE MANAGER 7839 01-MAY-81 2850 30
7782 CLARK MANAGER 7839 09-JUN-81 2450 10
7788 SCOTT ANALYST 7566 19-APR-87 3000 20
7839 KING PRESIDENT 17-NOV-81 5000 10
7844 TURNER SALESMAN 7698 08-SEP-81 1500 0 30
7876 ADAMS CLERK 7788 23-MAY-87 1100 20
7900 JAMES CLERK 7698 03-DEC-81 950 30
7902 FORD ANALYST 7566 03-DEC-81 3000 20
7934 MILLER CLERK 7782 23-JAN-82 1300 10
i. Name the Primary keys in both the tables and Foreign Key in EMP Table.
ii. In the table EMP, the v a l u e s i n DEPTNO f i e l d is repeated. Is there any discrepancy?
Give reason.
3. Write commands in SQL for (4) to (8) and Output for (9) and (10) : 6
i. To display ENAME, JOB, DEPTNO, DNAME and (SAL + COMM) * 12 as AnnualSalary for
those clients whose AnnualSalary is more than 150000. 2
ii. To display EMPNO, ENAME, D E P T N O and DNAME for e m p l o y e e s that have
“SALESMAN” as Job. 2
iii. SELECT ENAME, JOB,DNAME FROM EMP E, DEPT D
WHERE E.DEPTNO=D.DEPTNO AND E.JOB LIKE “A%T”; 2
Worksheet – 10
Time : 30 min M.M.10
Write answers at the back side of the sheet
1. Write SQL query to create a table ‘Participant’ with the following structure : 2
Field Type Constraint
ParticipantID Integer Primary key
Name Varchar(50)
ArrivalDate Date
DepartureDate Date
Phone Integer
EmailID Varchar(30)
2. In a database there are two tables ‘BRANDtab’ and ‘ITEM’ as shown below: 1+1
I.
How many rows and how many columns will be there in Cartesian product of these two
tables.
II. Which operations are possible on table BRANDtab and ITEM among the
following :
Selection, Projection, Cartesian Product, Union and Join.
3. Write SELECT Statement based on the table BRANDtab and ITEM given In ques 3. 2X3=06
i. To display ICODE, BRAND and INAME of those items who have 'N' anywhere in their NAME.
ii. To display ICODE, BRAND, INAME and PRICE for those items whose PRICE is between
50000 and 80000.
iii. SELECT I.ICODE, BRAND, COUNT(I.ICODE FROM ITEM I, BRANDtab B
WHERE I.ICODE = B.ICODE AND COUNT(I.ICODE)>1
GROUP BY I.ICODE;