You are on page 1of 24

Simple Queries

Worksheet-1

Q1. (a) Is MySQL case sensitive ? Explain with example.

(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.

(c) Consider the table KID shown below

Table : KID

Item Code Item DatePurchase UnitPrice Discount


101 Cot 2017-01-23 6000 25
102 Frock 2016-09-23 800 10
103 Soft Toy 2017-06-17 900 10
104 Baby Socks 2015-10-16 200 7
105 Baby Suit 2016-09-20 600 5
Write the query for command (i) to (viii) and output for (ix) to (x).

(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.

(ix) Select MID (Item, 1,2,) from Kid;

(x) Select AVG(UnitPrice) from Kid where DatePurchase> ‘2016-01-01’;


Worksheet-2

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

No Name Stipend Subject Average Division


1 Konditi 400 English 38 THIRD
2 Binny 680 Mathematics 72 FIRST
3 Kapil 500 Accounts 67 FIRST
4 Vijay 200 Informatics 55 SECOND
5 Anandha 400 History 85 FIRST
6 Upasna 550 Geography 45 THIRD
(i) To display details of those student who have got Division First and Average
is greater than 70.
(ii) To display details of all students also arrange the record in ascending order
of stipend received.
(iii) To display No and Name of all student while displaying display
“Admission Number” in place of column “No”
(iv) To list the names of those students, who have obtained Division as THIRD
in ascending order of NAME.
(v) To display a report listing NAME,SUBJECT and Annual stipend received
assuming that the stipend column has monthly stipend.
(vi) To count the number of students, who have either Accounts or Informatics
as subject.
(vii) To insert a new row in the table EXAM :
7, “Rama”, 600, “English”, 74, “Second”

(viii) SELECT MAX(Stipend) FROM RESULTSHEET WHERE DIVISION =


“THIRD”;
(ix) SELECT COUNT(DISTINCT Subject) FROM RESULTSHEET;
(x) SELECT MIN(Average) FROM RESULTSHEET WHERE Subject=
“Accounts”;

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.

INSERT INTO EMPLOYEE

VALUES (101, ‘Ved Prakash’, ‘Accounts’, 30000);

(b) What is the purpose of the following SQL query :

SELECT MAX(SALARY) FROM EMP;

(C) Consider the table Supplier given below. Write command in MySql for (i) to (vii) and
output for (viii) to (x) .

Table : Supplier

Scode Pname Supname Qty City Price


101 Cold Coffee Nestle 20 Bhopal 55.00
102 Parle Biscuit Hide & Seek 10 Delhi 10.00
103 Trim Jam Kissan 11 Bhopal 25.00
104 Salt Maggi Nestle 15 Mumbai 10.00
105 Chocolate Cadbury 17 Delhi 25.00
106 Soya Sauce Maggi 30 Mumbai 55.00
107 Milk Cake Britannia 70 Delhi 10.00
(i) To modify column City and write “New Delhi” in place of “Delhi”.
(ii) To display length (Number of character) of all Product Name.
(iii) Increase the price of all product by Rs. 5 whose current price is 50.
(iv) To drop column Price from table.
(v) To display names of the products, whose supname starts with ‘B’ in ascending
order of Price ?
(vi) To display Supplier code, Product name and City of the products whose quantity
is less than 15.
(vii) To count distinct City in the table.
(viii) Select Pname from supplier where Pname IN (“Bread”,”SaltMaggi”);
(ix) Select Count(distinct city) from supplier;
(x) Select max(Price) from supplier where City=”Bhopal” ;
WORK SHEET 6

1) Differentiate between TCL and DDL commands.

2) Write the output of the following SQL statements :

(i) Select char(66) as ‘Char’;


(ii) Select Concat(substr(“Ram”,2),”jain”) “StudentName”;
(iii) Select UPPER(“Rahul Kumar”);
(iv) Select RIGHT(“Informatics Practices”,5);

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.

(v) SELECT TRUNCATE(AvgMark,0) FROM Student WHERE AvgMark<85;


(vi) SELECT ROUND(AvgMark) FROM Student WHERE Grade=’A’;
(vii) SELECT CONCAT(Name, Stream) FROM Student WHERE Class = ‘11A’;
(viii) SELECT LEFT(Stream, 2) FROM Student;

WORKSHEET 7

1) Differentiate between group by and order by clause?

2)Write the output of the following SQL statements

i. SELECT CURDATE() AS ‘TODAY’;


iiSELECT DAYOFYEAR(‘2010-02-28’);

iii SELECT POW(2,3);

IV) SELECT DAYOFWEEK(CURDATE());

3 Consider the table GARMENTgiven below, write command in SQL for (a) to (d) and output for (e) to
(h).

Table : GARMENT

GCODE DESCRIPTION PRICE FCODE READYDATE

10023 PENCIL SKIRT 1150 F03 2015-11-19

10001 FORMAL SHIRT 1250 F01 2015-12-22

10012 INFORMALS 1550 F02 2015-12-05

10024 BABY TOP 750 F03 2015-11-30

10007 FORMAL PANT 1350 F01 2015-11-29

10009 FROCK 850 F04 2015-11-28


a. To display gcodeand description of each garment in descending order of GCODE.
b. To display the details of all the garments, which have READYDATEbetween ‘2015-11-19’ and ‘2015-
11-29’ (both values included).
c. To display average PRICE of all the garments whose FCODE is F03.
d. To display maximum and minimum PRICE from GARMENTS table.
e. select sum(price) from garment where fcode=’F01’;
f. select count(distinct fcode) from garment;
g. select gcode , price from garment where description like ‘%C%’;
h. select FCODE, PRICE from GARMENT where PRICE<1000;

WORKSHEET 8

1) What is the use of USE and DESCRIBE Command in My Sql?

2) Write the output of the following SQL statements

ii. SELECT ROUND(1023.432,1);


iii. SELECT UPPER(‘master’);
iv. SELECT LENGTH(‘ABS Public School’);
v. SELECT SUBSTR(TRIM(‘ABS Public School’,1,3);

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

1) How is Cross-Join different from Equi-Join?

2) Write output of the following MySQL queries :


i) SELECT DAYOFMONTH(NOW());
ii) SELECT ROUND(140.295,-2);
iii) SELECT INSTR(‘Corporation’, ‘or’);
iv) SELECT CONCAT(‘India’, NULL, ‘Australia’);

3 Consider the table EXAM given below. Write command in MySQL for (i) to (vi) and
output (v) to (viii).

No Name Stipend Subject Average Division

1 Karan 400 English 68 First

2 Aman 680 Maths 72 First

3 Javed 500 Accounts 67 First

4 Bishakh 200 Informatics 55 Second

5 Sugandha 400 History 35 Third

Suparna 550 Geography 45 Third

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.

2) Write the output of the following SQL queries.

(i) SELECT INSTR(‘CORPORATE FLOOR’,’OR’);


(ii) SELECT MID(‘Good Morning’,3,4);
(iii) SELECT LEFT('COMPUTER SCIENCE',7);
(iv) SELECT ROUND(366,1,-1);

3 Consider the table TEACHER given below. Write commands in SQL for (i) to (iv) and output for (v) to (viii)

ID Name Department Hiredate Category Gender salary

1 TanyaNanda Social 2004-03-17 TGT F 25000

2 Saurabh Sharma Art 2010-02-12 PRT M 20000

3 Nadita Arora English 2010-05-16 PGT F 30000

4 James Jacob English 2008-10-16 TGT M 25000

5 Jaspreet Kaur Hindi 2000-08-01 PRT F 22000

6 DishaSehgal Math 2008-03-17 PRT F 21000

7 Siddharth Kapoor Science 200-09-02 TGT M 27000

8 Sonali Mukherjee Math 2011-11-17 TGT F 24500


i. To display all information about teachers of PGT category.
ii. To list the names of female teachers of Hindi department.
iii. To listnames, departments, and hiring dates of all the teachers in ascending order of hiring dates.
iv. To count the number of teachers in English department.
v. SELECT MAX(Hiredate) FROM Teacher;
vi. SELECT DISTINCT(category) FROM Teacher;
vii. SELECT COUNT (*) FROM TeacherWHERE Category = ‘PGT’;
viii. SELECT AVG(Salary) FROM Teacher GROUP BY Gender;

Join Queries
Worksheet- 1
6(a) Write an SQL query to create the table “BookDetails“ with the following structure- 2

Field Type Constraint


Book_Id Varchar(4) Primary Key
Book_Name Varchar(30)
Author_Name char(30) Default “BPB”
Publisher Varchar(20)
Price Integer Check Price >0
Type Varchar(15)
Quantity Integer Not Null

(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?

c Consider the tables given below. 6


Table : STOCK
Itcod Itname Dcod Qty unitpr Stkdate
e e
452 Drawing Sheet 101 80 21 31-June-2017
457 Sharpener Camlin 102 65 13 21-Apr-2017
467 Eraser Natraj 101 40 6 11-Dec-2017
469 Gel Pen Montex 103 56 10 03-Jan-2017
407 Geometry Box 101 30 65 15-Nov-2017
421 Parker Premium 102 60 109 27-Oct-2017
427 Office File 103 20 34 13-Sep-2017

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:

P_Id LastName FirstName Address City


1 Gupta Naresh Railway Colony 14 Bhopal
2 Khan Wasim KV No 2 Raipur
3 Singh Sanjeev Radha Apartment Bhilai

The "Orders" table:

O_Id OrderN P_Id


o
1 77895 3
2 44678 3
3 22456 2
4 24562 1

Write MySQL queries for the following


(i) To display FistName, Address of all the persons with their corresponding OrderNo.
(ii) To display FisrtName , City and OrderNO where LastName begins with the letter ‘K’
(iii) To change the Address to LIC Colony 34 where the P_Id is equal to 1

Worksheet-3

6(a) Write SQL to Create the following table BANK with specified constraints 2

Column Name Data type Constraint


BankCode Character of 10 size Primary Key
Branch Character of 30 size
Location Character of 30 size City can have only four values “Hyderabad”,
”Delhi”,”Goa”,”Bhopal”
Budget Numeric(7,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

6(a) Consider the following EMP and DEPT table 6


Write the SQL command to get the following. (any 6)
a. Show the minimum, maximum and average salary of Managers.
b. Count the number of Clerk in the Organization.
c. Display the Designation wise list of employees with name, Sal and Date of Joining.
d. Count the number of employees who are not getting commission.
e. Show the average salary for all departments with more than 5 working people.
f. List the count of Employees grouped by DeptID.
g. Display the maximum salary of employees in each Department.
h. Display the name of Employees along with their Designation and Department Name.
i. Count the number of Employees working in ACCOUNTS department.

(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

Null/Uniqu Not null unique


e
Foreign Depart
Key table ment
name
Foreign DeptId
key
colomn
Data type integer char varchar integer double integer
Length 4 25 30 10 9,2 2
(c ) Does MySQL allow to change the primary key in all cases? If there is some special 2
case, please mention.
Worksheet-5

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

i) What should be the datatype of column PRICE.


ii) Write SQL command to Identify foreign key in ITEM table.

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

Column Name Data Type Size Constraint


Campus_id NUMBER 4 PRIMARY KEY
Campus_name VARCHAR 50 Not Null
City VARCHAR 20 Not Null
Pin NUMBER 7 Not Null
Phone NUMBER 10 Not Null

2. Consider the tables given below : 2

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

C101 A.K. Antony A-151, Adarsh Nagar 9910195614 80 P101


C102 Fauzia Aria K-5/52, Vikas Vihar 8934664481 500 P102
C103 Rashi Khanna D-6, Hakikat Nagar 9811665680 50 P101
76-A/2, MG Colony, Adarsh
i. C104
How manyS.K.
rows will be present in the Cartesian join of the9465877756
Chandra above mentioned 2100
tables? P104
ii. In the table ‘Client’, the PartyID 101 is present twice in the column “PartyId”. Is there any
discrepancy? Give reason.

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.

1. Create Table DEPT as per the structure given below : 2


Table : DEPT
Column Name Datatype Size Constraint
deptno integer Primary key
dname char 20 Not Null
loc char 20

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;

You might also like