KendriyaVidyalaya No-1 Armapur Kanpur

Subject-Computer Science

SQL PRACTICAL FILE FOR THE SESSION 2015-16
Index for Database and SQL
Name: ______Section: ___ Roll No.: ____
RNo. / Descriptions/Topics / Date / Sign.
1 / Introduction to database / About data, database
2 / About KEYS / PRIMARY,FOREIGN,CANDIDATE,ALTERNATE
3 / About Sql statements / Ddl,dmlstatements
4 / Database creation, deletion
5 / Sql commands for QUESTION-1
6 / Sql commands for QUESTION-2
7 / Sql commands for QUESTION-3
8 / Sql commands for QUESTION-4
9 / k-Map for sop with circuit diagram
10 / k-Map for pos with circuit diagram

Question No-1— Write SQL commands for the following on the basis of the given table CLUB.

TABLE-CLUB

COACH_ID / COACHNAME / AGE / SPORTS / DATEOFAPP / PAY / SEX
1 / KUKREJA / 35 / KARATE / 27/03/1996 / 1000 / M
2 / RAVINA / 34 / KARATE / 20/01/1998 / 1200 / F
3 / KARAN / 34 / SQUASH / 19/02/1998 / 2000 / M
4 / TARUN / 33 / BASKETBALL / 01/01/1998 / 1500 / M
5 / ZUBIN / 36 / SWIMMING / 12/01/1998 / 750 / M
6 / KETAKI / 36 / SWIMMING / 24/02/1998 / 800 / F
7 / ANKITA / 39 / SQUASH / 20/02/1998 / 2200 / F
8 / ZAREEN / 37 / KARATE / 22/02/1998 / 1100 / F
9 / KUSH / 41 / SWIMMING / 13/01/1998 / 900 / M
10 / SHAILYA / 37 / BASKETBALL / 19/02/1998 / 1700 / M

a)To Show all information about the swimming coaches in the club.

b)To list names of all coaches with their date of appointment (DATEOFAPP) in descending order.

c)To display a report, showing coach name, pay, age and bonus (15% of pay) for all the coaches.

d)Give the output of the following SQL statements:

  1. SELECT LCASE(SPORTS) FROM CLUB;
  2. SELECT MOD(AGE,5) FROM CLUB WHERE SEX=’F’;
  3. SELECT POWER(3,2) FROM CLUB WHERE SPORTS=’KARATE’;
  4. SELECT SubStr(COACHNAME,1,2) FROM CLUB WHERE DATEOFAPP>’31/01/1998’;

e)Give the output of the following SQL statements:

  1. SELECT COUNT (DISTINCT SPORTS) FROM CLUB;
  1. SELECT MIN(AGE) FROM CLUB WHERE SEX=’F’;
  2. SELECT AVG(PAY) FROM CLUB WHERE SPORTS=’KARATE’;
  3. SELECT SUM(PAY) FROM CLUB WHERE DATEOFAPP>’31/01/1998’;

Question No-2—Write SQL commands for the following on the basis of the given table STUDENT.

TABLE-STUDENT

No. / Name / Stipend / Stream / AvgMark / Grade / Class
1 / KARAN / 400.00 / Medical / 78.5 / B / 12B
2 / DIVAKAR / 450.00 / Commerce / 89.2 / A / 11C
3 / DIVYA / 300.00 / Commerce / 68.6 / C / 12C
4 / ARUN / 350.00 / Humanities / 73.1 / B / 12C
5 / SABINA / 500.00 / Nonmedical / 90.6 / A / 11A
6 / JOHN / 400.00 / Medical / 75.4 / B / 12B
7 / ROBERT / 250.00 / Humanities / 64.4 / C / 11A
8 / RUBINA / 450.00 / Nonmedical / 88.5 / A / 12A
9 / VIKAS / 500.00 / Nonmedical / 92.0 / A / 12A
10 / MOHAN / 300.00 / Commerce / 67.5 / C / 12C

a)Select the entire Nonmedical stream from STUDENT.

b)List the names of those students who are in class 12 sorted by Stipend.

c)List all students sorted by AvgMark in descending order.

d)To display a report, listing Name, Stipend, Stream and amount of Stipend received in a year assuming that the Stipend is paid every month.

e)Give the output of the following SQL statements:

  1. SELECT TRUNCATE(AvgMark,0) FROM STUDENT WHERE AvgMark<75;
  2. SELECT ROUND(AvgMark) FROM STUDENT WHERE Grade=’B’;
  3. SELECT CONCAT(Name, Stream) FROM STUDENT WHERE Class=’12A’;
  4. SELECT RIGHT(Stream,2) FROM STUDENT ;

f)Give the output of the following SQL statements:

  1. SELECT MIN(AvgMark) FROM STUDENT WHERE AvgMark<75;
  2. SELECT SUM(Stipend) FROM STUDENT WHERE Grade=’B’;
  3. SELECT AVG(Stipend) FROM STUDENT WHERE Class=’12A’;
  4. SELECT COUNT(DISTINCT Name) FROM STUDENT ;

Question No-3— consider the following tables. Write SQL commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii).

Table-SENDER

SenderID / SenderName / SenderAddress / SenderCity
ND01 / R Jain / 2,ABC Appts / New Delhi
MU02 / H Sinha / 12, Newtown / Mumbai
MU15 / S Jha / 27/A,Park Street / Mumbai
ND50 / T Prasad / 122-K,SDA / New Delhi

Table-RECIPIENT

RecID / SenderID / RecName / RecAddress / RecCity
KO05 / ND01 / R Bajpayee / 5, Central Avenue / Kolkata
MU19 / ND01 / H Singh / 2A, Andheri East / Mumbai
MU32 / MU15 / P K Swamy / B5, C S Terminus / Mumbai
ND08 / MU02 / S Mahajan / 116, A Vihar / New Delhi
ND48 / ND50 / S Tripathi / 13, B1 D, MayurVihar / New Delhi
  1. To display the names of all Senders from Mumbai.
  2. To display the RecID, SenderName, SenderAddress, RecName, RecAddress for every Recipient.
  3. To display Recipient details in ascending order of the RecName.
  4. To display number of Recipients from each city.
  5. SELECT DISTINCT SenderCity from SENDER;
  6. SELECT A.SenderName,B.RecName

FROM SENDERA,Recipient B

WHERE A.SenderID=B.SenderID AND B.RecCity=’Mumbai’;

  1. SELECT RecName,RecAddressFROM RECIPIENTWHERE RecCity NOT IN(‘Mumbai’,’Kolkata’);
  2. SELECT RecID,RecName

FROM RECIPIENT

WHERE SenderID=’M02’ OR SenderID=’ND50’;