20
1 MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834 1 QUESTION BANK – SQL Q.1. Table : SchoolBus Rtno Area_Covered Capacity Noofstudents Distance Transporter Charges 1 Vasant kunj 100 120 10 Shivamtravels 100000 2 Hauz Khas 80 80 10 Anand travels 85000 3 Pitampura 60 55 30 Anand travels 60000 4 Rohini 100 90 35 Anand travels 100000 5 Yamuna Vihar 50 60 20 Bhalla Co. 55000 6 Krishna Nagar 70 80 30 Yadav Co. 80000 7 Vasundhara 100 110 20 Yadav Co. 100000 8 Paschim Vihar 40 40 20 Speed travels 55000 9 Saket 120 120 10 Speed travels 100000 10 Jank Puri 100 100 20 Kisan Tours 95000 i. To show all information of students where capacity is more than the no of student in order of rtno. ii. To show area_covered for buses covering more than 20 km., but charges less then 80000. iii. To show transporter wise total no. of students traveling. iv. To show rtno, area_covered and average cost per student for all routes where average cost per student is - charges/noofstudents. v. Add a new record with following data: vi. (11, “ Moti bagh”,35,32,10,” kisan tours “, 35000) vii. Give the output considering the original relation as given: viii. select sum(distance) from schoolbus where transporter= “ Yadav travels”; ix. select min(noofstudents) from schoolbus; x. select avg(charges) from schoolbus where transporter= “ Anand travels”; xi. select distinct transporter from schoolbus; xii. Display total distance covered by transporter “Anand Travels”. xiii. Display total distance covered by each transporter. xiv. How many transporter are there? Q2. TABLE : GRADUATE S.NO NAME STIPEND SUBJECT AVERAGE DIV. 1 KARAN 400 PHYSICS 68 I 2 DIWAKAR 450 COMP. Sc. 68 I 3 DIVYA 300 CHEMISTRY 62 I 4 REKHA 350 PHYSICS 63 I 5 ARJUN 500 MATHS 70 I 6 SABINA 400 CEHMISTRY 55 II 7 JOHN 250 PHYSICS 64 I 8 ROBERT 450 MATHS 68 I 9 RUBINA 500 COMP. Sc. 62 I 10 VIKAS 400 MATHS 57 II i. List the names of those students who have obtained DIV 1 sorted by NAME. ii. Display a report, listing NAME, STIPEND, SUBJECT and amount of stipend received in a year assuming that the STIPEND is paid every month. iii. To count the number of students who are either PHYSICS or COMPUTER SC graduates. iv. To insert a new row in the GRADUATE table: i. 11,”KAJOL”, 300, “computer sc”, 75, 1 v. Give the output of following sql statement based on table GRADUATE:

QUESTION BANK - SQLmscclucknow.com/downloads/cbseXIIip/QUESTION BANK - SQL.pdf · 2014. 2. 12. · 1 MOHIT TANDON 9839013528, 9838453834 1 QUESTION BANK – SQL Q.1. Table : SchoolBus

  • Upload
    others

  • View
    15

  • Download
    0

Embed Size (px)

Citation preview

  • 1

    MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

    1

    QUESTION BANK – SQL

    Q.1. Table : SchoolBus

    Rtno Area_Covered Capacity Noofstudents Distance Transporter Charges

    1 Vasant kunj 100 120 10 Shivamtravels 100000

    2 Hauz Khas 80 80 10 Anand travels 85000

    3 Pitampura 60 55 30 Anand travels 60000

    4 Rohini 100 90 35 Anand travels 100000

    5 Yamuna Vihar 50 60 20 Bhalla Co. 55000

    6 Krishna Nagar 70 80 30 Yadav Co. 80000

    7 Vasundhara 100 110 20 Yadav Co. 100000

    8 Paschim Vihar 40 40 20 Speed travels 55000

    9 Saket 120 120 10 Speed travels 100000

    10 Jank Puri 100 100 20 Kisan Tours 95000

    i. To show all information of students where capacity is more than the no of student in order of rtno. ii. To show area_covered for buses covering more than 20 km., but charges less then 80000.

    iii. To show transporter wise total no. of students traveling. iv. To show rtno, area_covered and average cost per student for all routes where average cost per

    student is - charges/noofstudents.

    v. Add a new record with following data: vi. (11, “ Moti bagh”,35,32,10,” kisan tours “, 35000)

    vii. Give the output considering the original relation as given: viii. select sum(distance) from schoolbus where transporter= “ Yadav travels”;

    ix. select min(noofstudents) from schoolbus; x. select avg(charges) from schoolbus where transporter= “ Anand travels”;

    xi. select distinct transporter from schoolbus; xii. Display total distance covered by transporter “Anand Travels”.

    xiii. Display total distance covered by each transporter. xiv. How many transporter are there?

    Q2. TABLE : GRADUATE

    S.NO NAME STIPEND SUBJECT AVERAGE DIV.

    1 KARAN 400 PHYSICS 68 I

    2 DIWAKAR 450 COMP. Sc. 68 I

    3 DIVYA 300 CHEMISTRY 62 I

    4 REKHA 350 PHYSICS 63 I

    5 ARJUN 500 MATHS 70 I

    6 SABINA 400 CEHMISTRY 55 II

    7 JOHN 250 PHYSICS 64 I

    8 ROBERT 450 MATHS 68 I

    9 RUBINA 500 COMP. Sc. 62 I

    10 VIKAS 400 MATHS 57 II

    i. List the names of those students who have obtained DIV 1 sorted by NAME. ii. Display a report, listing NAME, STIPEND, SUBJECT and amount of stipend received in a year

    assuming that the STIPEND is paid every month.

    iii. To count the number of students who are either PHYSICS or COMPUTER SC graduates. iv. To insert a new row in the GRADUATE table:

    i. 11,”KAJOL”, 300, “computer sc”, 75, 1 v. Give the output of following sql statement based on table GRADUATE:

  • 2

    MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

    2

    a. Select MIN(AVERAGE) from GRADUATE where SUBJECT=”PHYSICS”; b. Select SUM(STIPEND) from GRADUATE WHERE div=2; c. Select AVG(STIPEND) from GRADUATE where AVERAGE>=65; d. Select COUNT(distinct SUBDJECT) from GRADUATE;

    (b) Assume that there is one more table GUIDE in the database as shown below:

    Table: GUIDE

    What will be the output of the following query:

    SELECT NAME, ADVISOR FROM GRADUATE,GUIDE WHERE SUBJECT= MAINAREA;

    Q3. Table: SPORTS

    i. Display the names of the students who have grade „C‟ in either Game1 or Game2 or both. ii. Display the number of students getting grade „A‟ in Cricket.

    iii. Display the names of the students who have same game for both Game1 and Game2. iv. Display the games taken up by the students, whose name starts with „A‟. v. Assign a value 200 for Marks for all those who are getting grade „B‟or grade „A‟ in both Games1&2

    vi. Arrange the whole table in the alphabetical order of Name. vii. Add a new column named „Marks‟. Q4. Employees

    Empid Firstname Lastname Address City

    010 Ravi Kumar Raj nagar GZB

    105 Harry Waltor Gandhi nagar GZB

    152 Sam Tones 33 Elm St. Paris

    215 Sarah Ackerman 440 U.S. 110 Upton

    44 Manila Sengupta 24 Friend street New Delhi

    300 Robert Samuel 9 Fifth Cross Washington

    335 Ritu Tondon Shastri Nagar GZB

    400 Rachel Lee 121 HarrisonSt. New York

    EmpSalary

    i. To show firstname,lastname,address and city of all employees living in paris

    MAINAREA ADVISOR

    PHYSICS VINOD

    COMPUTER SC ALOK

    CHEMISTRY RAJAN

    MATHS MAHESH

    Student NO Class Name Game1 Grade Game2 Grade2

    10 7 Sammer Cricket B Swimming A

    11 8 Sujit Tennis A Skating C

    12 7 Kamal Swimming B Football B

    13 7 Venna Tennis C Tennis A

    14 9 Archana Basketball A Cricket A

    15 10 Arpit Cricket A Atheletics C

    Empid Salary Benefits Designation

    010 75000 15000 Manager

    105 65000 15000 Manager

    152 80000 25000 Director

    215 75000 12500 Manager

    244 50000 12000 Clerk

    300 45000 10000 Clerk

  • 3

    MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

    3

    ii. To display the content of Employees table in descending order of Firstname. iii. To display the firstname,lastname and total salary of all managers from the tables Employee and

    empsalary , where total salary is calculated as salary+benefits.

    iv. To display the maximum salary among managers and clerks. v. Display total no. of employees in each city.

    vi. Display total salary for each designation of employee. vii. Display empid,firstname and salary of those employees that are earning salary equal to empid 010.

    viii. Give the Output of following SQL commands: a. Select firstname,salary from employees ,empsalary where designation = „Salesman‟ and

    Employees.empid=Empsalary.empid;

    b. Select count(distinct designation) from empsalary; c. Select designation, sum(salary) from empsalary group by designation having count(*) >2; d. Select sum(benefits) from empsalary where designation =‟Clerk‟.

    Q5(a) What is relation? Define degree of relation.

    (b) Write SQL queries for the following:-

    TABLE : LAB

    No ItemName CostPerItem Quantity Dateofpurchase Warranty Operational

    1 Computer 60000 9 21/5/96 2 7

    2 Printer 15000 3 21/5/97 4 2

    3 Scanner 18000 1 29/8/98 3 1

    4 Camera 21000 2 13/10/96 1 1

    5 Hub 8000 1 31/10/99 2 1

    6 UPS 5000 5 21/5/96 1 4

    7 Plotter 25000 2 11/1/2000 2 5

    i. To select the ItemName,which are within the Warranty period till present date. ii. To list the ItemName in ascending order of the date of purchase where quantity is more than 3.

    iii. Display total no. of items purchased in year 1996. iv. How many items are within warranty period. v. Display total cost of each item.

    vi. Display those items that are having warranty as that of Computer. vii. Give the output of the following SQL commands:

    select min(DISTINCT Quantity) from LAB;

    select sum(CostPerItem) from Lab;

    select ItemName from LAB where sysdate - DateofPurchase>1;

    Q.6. TABLE: OFFICE

    Empno Empname Age Department gender B_Pay

    1 Ankit 45 Comp.Sc. M 10000

    2 Sumit 32 History M 6000

    3 Suchitra 23 Maths F 9000

    4 Amit 25 Geography M 5000

    5 Ankita 26 Hindi F 8500

    6 Shurti 28 Comp.Sc. F 7200

    7 Rakesh 35 Hindi M 5900

    8 Priya 33 History F 10500

    i. Display details of all employees belonging to History and Geography department. ii. Display average age of employee department wise.

    iii. Display no. of employees in each department where number of employees are more than or equal to 2.

  • 4

    MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

    4

    iv. Display details of all female employee belonging to various departments except in Maths and History.

    v. Display name and age of those employees getting basic pay between 6000 and 10000. vi. How many employees are working in Comp. Sc. Deptt.

    vii. How many deptt. are there in a office. viii. How many teachers are working in same deptt. as that of Ankita.

    ix. Display total pay of employees of each gender. x. Display the maximum pay among male teachers.

    xi. Give output of following:- a. Select sum(B_pay) from OFFICE; b. Select count (*) from OFFICE where name like „A%‟; c. Select empname from OFFICE where age in (select max(age) from OFFICE);

    Q.7 TABLE :BOOKS:

    Book_id Book_name Author_name Publishers Price Type Qty.

    K0001

    P0001

    M0001

    N0002

    K0002

    Sanjeev & Sanjeev

    Genuine

    Mastering c++

    Vc++

    Advance Java

    Sanjay Kumar.

    Kanetkar

    S. Mukharjee

    J. Mukhi

    P. Purohit

    EPB

    FIRST PUBL.

    EPB

    TDH

    FIRST PUBL.

    755

    1650

    350

    150

    2341

    Cookery

    Fiction

    Text

    Text

    Fiction

    15

    20

    89

    78

    16

    TABLE : ISSUED

    Book_id Quantity_issued

    K0002

    P0001

    M0001

    4

    5

    2

    i. To show book name, author name and price of books of First Publishers. ii. To list the names from books of text type.

    iii. To display the names and price form books in ascending order of their price. iv. To increase the price of all books of epb publishers by 50. v. To display the book_id,book_name and quantity_issued for all books which have been issued.

    vi. To insert a new row in the table issued having the following data : “N0002 ”, 16 vii. Remove the records of books of “text” type.

    viii. How many books are of each type. ix. Give the output of the following queries based on the above tales:

    a. select count(*)from books; b. select max(price) from books where quantity>=15; c. Select book_name,author_name from books where publishers = “EPB”; d. Select count (distinct publishers) from books where price>=400;

    Q. 8. a) Differenciate between primary key and Unique key.

    b) Consider the following tables SCHOOL and ADMIN. Write SQL commands for the statements (i) to (iv)

    and give outputs for SQL queries (v) to (viii).

    Table: SCHOOL

    Code

    Teacher

    name

    Subject Doj Periods Experience

    01 Ravi Shankar English 12/03/2000 24 10

    1009 Priya Rai Physics 03/09/1998 26 12

    1203 Lisa Anand English 09/04/2000 27 5

    045 Yashraj Maths 24/08/2000 24 15

    1123 Ganan Physics 16/07/1999 28 3

    1167 Harish B Chemis

    try

    19/10/1999 27 5

  • 5

    MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

    5

    1215 Umesh Physics 11/05/1998 22 16

    Table : 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 the teachers whose periods are less than 25 in ascending

    order of teacher name .

    ii) To display TEACHERNAME, CODE and DESIGNATION from tables SCHOOL and ADMIN.

    iii) To display the subject wise TEACHERNAME who have minimum PERIODS.

    iv) To display CODE,TEACHERNAME & SUBJECT of all teachers who have joined school after

    1/1/1999.

    v) Display max. experience in each subject.

    vi) Display teachername and gender of each teacher.

    vii) Display total no. of teachers in each designation where count < 3.

    viii) how many subjects are there?

    Q.9. TABLE : SUPPLIER

    SUPNO Pname Sname Qty Price City

    S1 Bread Britania 150 8.00 Bangalore

    S2 Cake Britania 200 20.00 Bangalore

    S3 Coffee Nescafe 50 25.00 Delhi

    S4 Chocolate Amul 500 12.00 Chennai

    S5 Souce Kissan 250 15.00 Chennai

    S6 Maggi Nestle 25 30.00 Delhi

    S7 Jam Kissan 70 50.00 Chennai

    S8 Biscut 100 10.00 Bangalore

    i. Display data for all products whose quantity is between 170 and 370. ii. Display all the products that have no supplier.

    iii. Give Sname for that entire product whose name start with “C”. iv. Display for all products sorted by their quantity. v. Give the output of the following SQL commands:

    a. select Avg(price) from SUPPLIERS where Price>30; b. select Max(price) from SUPPLIER where Price

  • 6

    MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

    6

    Select Pname, P# from SUPPLIER, PRODUCT Where City = Pcity;

    Q.10. a) What do you understand by DOMAIN and TUPLE of a RELATION?

    b) Write SQL commands for (i) to (vi) and write the outputs for (vii) on the basis of

    table Hospital.

    Table: Hospital

    No. Name Age Department Dateofadm Charges Sex

    1 Sandeep 65 Surgery 23/02/98 300 M

    2 Ravina 24 Orthopedic 20/01/98 200 F

    3 Karan 45 Orthopedic 19/02/98 200 M

    4 Tarun 12 Surgery 01/01/98 300 M

    5 Zubin 36 ENT 12/01/98 250 M

    6 Ketaki 16 ENT 24/02/98 300 F

    7 Leena 29 Cardiology 20/02/98 800 F

    8 Zareen 45 Gynecology 22/02/98 300 F

    9 Kush 19 Cardiology 13/01/98 800 M

    10 Shailya 31 Nuclear Medicine 19/02/98 400 F

    i. To show all information about the patients of cardiology department. ii. To list the names of female patients who are in orthopedic department.

    iii. To list names of all patients with their date of admission in ascending order. iv. To display patient‟s Name, Charges, AGE for only male patients only. v. To count the number of patients with Age greater than 30.

    vi. To insert a new row in the Hospital table with the following data: vii. 11, “ Nipan “, 26 , “ENT”, {25/02/98}, 50, “ M “

    Give the output of following SQL statements:

    viii. Select COUNT(distinct Department) from Hospital; ix. Select MAX(Age) from Hospital where Sex = “M”; x. Select AVG(Charges) from Hospital where Sex = “ F “;

    xi. Select SUM(Charges) from Hospital where Dateofadm < {12/08/98}

    Q.11. a) What do you understand by Primary Key.

    b) Consider the following tables Employee and salary. Write SQL commands for the statements (i)

    to (iv) and give outputs for SQL queries (v) to (viii)

    Table : Employee

    Eid Name Deptid Qualification Sex

    1 Deepali Gupta 101 MCA F

    2 Rajat Tyagi 101 BCA M

    3 Hari Mohan 102 B.A M

    4 Harry 102 M.A M

    5 Sumit Mittal 103 B.Tech M

    6 Jyoti 101 M.Tech F

    Table : Salary

    Eid Basic DA HRA Bonus

    1 6000 2000 2300 200

    2 2000 300 300 30

    3 1000 300 300 40

    4 1500 390 490 30

    5 8000 900 900 80

    6 10000 300 490 89

    i. To display the frequency of employees department wise.

  • 7

    MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

    7

    ii. To list the names of those employees only whose name starts with „H‟

    iii. To add a new column in salary table . the column name is total_sal.

    iv. To store the corresponding values in the total_sal column.

    v. Select name from employee where eid=(select eid from salary where basic= (select max(basic)

    from salary));

    vi. select max(basic) from salary where bonus >40;

    vii. Select count(*) from employee group by sex;

    viii. select Distinct deptid from Employee;

    Q.12. Write SQL commands for (i) to (vii) on the basis of the table LAB

    Table : LAB

    NO

    ITEM

    NAME

    COST QTY DATEOFPURCHASE WARRANTY OPERATIONAL

    1. COMPUTER 45000 9 21/5/96 2 7

    2. PRINTER 15000 3 21/5/97 4 2

    3. SCANNER 21000 1 29/8/98 3 1

    4. CAMERA 12000 2 13/6/96 1 2

    5. HUB 4000 1 31/10/99 2 1

    6. UPS 5000 5 21/5/96 1 4

    7. PLOTTER 13000 2 11/1/2000 2 2

    i) to select the item name purchased after 31/10/97.

    ii) to list item name, which are within the warranty period till present date

    iii) to list the name in ascending order of the date of purchase where quantity is more than 3.

    iv) to count the number of items whose cost is more than 10000.

    v) Give the output of the following SQL commands :

    a) SELECT MIN(DISTINCT QTY) FROM LAB;

    b) SELECT MIN(WARRANTY) FROM LAB WHERE QTY=2 ;

    c) SELECT SUM(COST) FROM LAB WHERE QTY>2 ;

    d) SELECT AVG(COST) FROM LAB WHERE DATEOFPURCHASE

  • 8

    MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

    8

    (ii) To display the details of Products whose Price is in the range of 50 to 100 (Both values included).

    (iii) To display the ClientName, City from table Client, and ProductName and Price from table Product, with

    their corresponding matching P_IO.

    (iv) To increase the Price of all Products by 10.

    (v) SELECT DISTINCT City FROM Client;

    (vi)SELECT Manufacturer, MAX(PRICE), MIN(PRICE), Count(*) from Product group by Manufacturer.

    (vii) SELECT ClientName, ManufacturerName from Product, Client where Client.Prod_Id=Product.P_Id;

    (viii) SELECT ProductName, Price* 4 From Product;

    Q.14. . a) Write the difference(s) between union & Cartesian product with example.

    b) Consider the tables ITEMS & COMPANY. Write SQL commands for the statements (i) to (iv) and

    give the outputs for SQL queries (v) & (vi) .

    Table : ITEMS

    ID PNAME PRICE MDATE QTY

    T001 Soap 12.00 11/03/2007 200

    T002 Paste 39.50 23/12/2006 55

    T003 Deodorant 125.00 12/06/2007 46

    T004 Hair Oil 28.75 25/09/2007 325

    T005 Cold

    Cream

    66.00 09/10/2007 144

    T006 Tooth

    Brush

    25.00 17/02/2006 455

    Table : COMPANY

    ID COMP City

    T001 HLL Mumbai

    T006 Colgate Delhi

    T009 HLL Mumbai

    T007 Paras Haryana

    T005 Ponds Noida

    T0011 Wipro Ahmedabad

    i) Display the items detail produced by Wipro & Paras.

    ii) To display product name, company name & price for those items which IDs are equal to the

    IDs of company.

    iii) To delete the items produced before 2007.

    iv) To display the total stock value of items.

    Q.16. a. What do you understand by the terms Cardinality and Degree of a relation in

    relational database?

    b. Study the following tables CPU and MONITOR and write SQL commands

    for the questions (i) to (iv) and give outputs for SQL queries (v) to (vi).

    Table : MONITOR

    TAB_NO MAKE COLOR MODEL YEAR MON_NO

    1 Zenith Black CRT 2004 Z_08

    2 Samsung White CRT 2004 S_01

    3 Samsung White CRT 2004 S_02

    4 LG Black LCD 2008 L_01

  • 9

    MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

    9

    5 LG Black LCD 2008 L_02

    6 LG Black LCD 2008 L_03

    7 LG Black LCD 2008 L_04

    Table : CPU

    TAB_NO

    MODEL COLOR YEAR CPU_NO

    1 Zenith Black 2003 Z_12

    2 Zenith Black 2003 Z_08

    3 Wipro Black 2005 W_04

    4 Wipro Black 2006 W_24

    5 Wipro Black 2008 W_25

    6 LG Gray 2008 L_01

    7 LG Gray 2008 L_02

    i. Display the model, year of all the CPU‟s whose color is black and CPU no. starts with „L‟ or „W‟ and the record of CPU purchased last must be displayed first.

    ii. List those CPU‟s that are purchased in the same year as that of monitors. iii. Display the model & year of CPU, make of monitor, price of monitor that has CPU and monitor

    color black.

    iv. Display number of monitor models of both CRT and LCD type separately. v. Display total price of monitors of each make. vi. How many types of CPU‟s are there? Give output of following:-

    vii. Select count(make) from monitor where year between 2003 and 2007; viii. Select sum(price) from monitor where price >3200 and price < 5000 and model=‟LCD‟;

    Q.17. a. What do you understand by the terms DDL and DML in relational database?

    b. Study the following tables CPU and MONITOR and write SQL commands for the questions (i) to

    (iv) and give outputs for SQL queries (v) to (vi).

    Table : TOUR

    SNO STUNO NAME STD DELHI CHENNAI POCKET

    1 B01 Arun XII LB MB 2000

    2 B02 Alex XII MB UB 2500

    3 B03 Arjun XII LB LB 2000

    4 B04 Amar XII UB UB 1500

    5 G01 Annie XII LB LB 2500

    6 G02 Avanthika XII MB UB 1500

    7 G03 Ashwini XII UB MB 3500

    Table : ACCOMODATION

  • 10

    MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

    10

    STUNO ROOMNO FLOOR FOOD

    B01 201 II Veg

    B02 201 II N Veg

    B03 202 II N Veg

    B04 202 II Veg

    G01 402 IV Veg

    G02 402 IV Veg

    G03 403 IV Veg

    Note :

    In Stuno B stands for Boys and G stands for Girls

    Delhi refers Train to Delhi

    Chennai refers Train to Chennai

    LB – Lower Berth

    MB – Middle Berth

    UB – Upper Berth

    ix. Display the details of student who got lower berth in both Delhi and Chennai train. x. Display the name of students whose food choice is Veg. xi. Display the number of rooms booked by the student. xii. Display the room number and sum of pocket money of students staying in that room. xiii. select tour.stuno, name, roomno from tour, accomodation where accomodation.stuno =

    tour.stuno;

    xiv. select count(pocket), sum (pocket) from tour, accomodation where tour.stuno = accomodation.stuno AND food ='N Veg';

    Q.18. a. Differentiate between Candidate Key and Alternate Key in context of RDBMS.

    b. Consider the following tables Item and Customer. Write SQL commands for the

    statements (i) to (iv) and give outputi for SQL queries (v) to (viii).

    TABLE: ITEM

    I_ID ItemName Manufacturer Price

    PC01 Personal Computer ABC 35000

    LC05 Laptop ABC 55000

    PC03 Personal Computer XYZ 32000

    PC06 Personal Computer COMP 37000

    LC03 Laptop PQR 57000

    TABLE : CUSTOMER

    C_ID CustomerName City I_Id

    01 N Roy Delhi LC03

    06 H Singh Mumbai PC03

    12 R Pandey Delhi PC06

  • 11

    MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

    11

    15 C Sharma Delhi LC03

    16 K Agarwal Bangalore PC01

    (i) To display the details of those Customers whose City is Delhi

    (ii) To display the details of Items whose Price is in the range of 35000 to 55000 (Both

    values included)

    (iii) To display the CustomerNarne, City from table Customer and ItemName and Price from table Item,

    with their corresponding matching I_Id

    (iv) To increase the Price of all Items by 1000 in the table Item

    (v) SELECT DISTINCT City FROM Customer;

    (vi) SELECT ItemName, MAX(Price), Count(*)

    FROM Item GROUP BY ItemName;

    (vii) SELECT CustomerName, Manufacturer

    FROM Item, Customer

    WHERE Item.Item_Id=Customer.ItemI_Id

    (viii) SELECT ItemName, Price * 100

    FROM Item WHERE Manufacturer='ABC';

    Q.19. a. Differentiate between Degree and Cardinality in context of RDBMS.

    b. Consider the following tables GAMES and PLAYER. Write SQL commands

    for the statements (i) to (iv) and give outputs for SQL queries (v) to (viii)

    Table: GAMES

    GCode GameName Number PrizeMoney ScheduleDate

    101 Carom Board 2 5000 23-Jan-2004

    102 Badminton 2 12000 12-Dec-2003

    103 Table Tennis 4 8000 14-Feb-2004

    105 Chess 2 9000 01-Jan-2004

    108 Lawn Tennis 4 25000 19-Mar-2004

    Table: PLAYER

    PCode Name Gcode

    1 Nabi Ahmad 101

    2 Ravi Sahai 108

    3 Jatin 101

    4 Nazneen 103

    (i) To display the name of all Games with their Gcodes

    (ii) To display details of those games which are having PrizeMoney more than 7000.

    (iii) To display the content of the GAMES table in ascending order of ScheduleDate.

    (iv) To display sum of PrizeMoney for each of the Number of participation groupings (as shown

    in column Number 2 or 4)

    (v) SELECT COUNT(DISTINCT Number) FROM GAMES; (vi) SELECT MAX(ScheduleDate),MIN(ScheduleDate) FROM GAMES;

    (vii) SELECT SUM(PrizeMoney) FROM GAMES;

    (viii) SELECT DISTINCT Gcode FROM PLAYER;

  • 12

    MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

    12

    Q.20. a) What do you understand by the terms Candidate key and Cardinality of a relation?

    b) Consider the following tables FACULTY and COURSES.

    c) Write SQL commands for the statements (i) to (iv) and give outputs for SQL

    queries (v) to (viii)

    FACULTY

    F_ID Fname Lname Hire_date Salary

    102 Amit Mishra 12-10-1998 12000

    103 Nitin Vyas 24-12-1994 8000

    104 Rakshit Soni 18-5-2001 14000

    105 Rashmi Malhotra 11-9-2004 11000

    106 Sulekha Srivastava 5-6-2006 10000

    107 Niranjan Kumar 26-8-1996 16000

    COURSES

    C_ID F_ID Cname Fees

    C21 102 Grid Computing 40000

    C22 106 System Design 16000

    C23 104 Computer Security 8000

    C24 106 Human Biology 15000

    C25 102 Computer Network 20000

    C26 105 Visual Basic 6000

    C27 107 Dreamweaver 4000

    (i) To display details of those Faculties whose date of joining is before 31-12-2001. (ii) To display the details of courses whose fees is in the range of 15000 to 50000 (both values included).

    (iii) To increase the fees of Dreamweaver course by 500. (iv) To display F_ID, Fname, Cname of those faculties who charged more than15000 as fees. (v) Select COUNT(DISTINCT F_ID) from COURSES; (vi) Select MIN(Salary) from FACULTY,COURSES where COURSES.F_ID = FACULTY.F_ID;

    (vii) Select SUM(Fees) from courses Group By F_ID having count(*) > 1;

    (viii) Select Fname, Lname from FACULTY Where Lname like “M%”;

    Q.21. (a) Differentiate between primary key and alternate key.

    (b) Consider the following tables SCHOOL and ADMIN. Write SQL commands

    for the statements (1) to (4) and give outputs for SQL queries (5) to (8).

    Table: SCHOOL

    CODE TEACHERNAME SUBJECT DOJ PERIODS EXPERIENCE

    1001 RAVI SHANKAR ENGLISH 12/03/2000 24 10

    1009 PRIYA RAI PHYSICS 03/09/1998 26 12

    1203 LISA ANAND ENGLISH 09/04/2000 27 5

    1045 YASHRAJ MATHS 24/08/2000 24 15

    1123 GANAN PHYSICS 16/07/1999 28 3

    1167 HARISH B CHEMISTRY 19/10/1999 27 5

    1215 UMESH PHYSICS 11/05/1998 22 16

    Table: ADMIN

    CODE GENDER DESIGNATION BASIC PERKS

    1001 MALE VICE PRINCIPAL 25000 5000

    1009 FEMALE COORDINATOR 22000 4000

  • 13

    MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

    13

    1203 FEMALE COORDINATOR 20500 3000

    1045 MALE HOD 18000 2000

    1123 MALE SENIOR TEACHER 15000 1000

    1167 MALE SENIOR TEACHER 13500 1000

    1215 MALE HOD 17000 2000

    i. To display TEACHERNAME, PERIODS of all teachers whose periods less than 25 and name start with either R or U.

    ii. Display the names, subject and total salary of all male teachers where salary is the sum of Basic and perks.

    iii. To display TEACHERNAME, CODE and DESIGNATION from tables SCHOOL and ADMIN for female teacher.

    iv. To display CODE, TEACHERNAME and SUBJECT of all teachers who have joined the school after 01/01/1999.

    v. Select Sum(Salary), Designation From Admin Group By Designation; 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 (*)

  • 14

    MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

    14

    2000

    iv) Display the average salary given to the employee in each department v) SELECT DEPT, COUNT(*) FROM STAFF WHERE SEX=‟m‟ GROUP BY DEPT

    HAVING COUNT(*) >2

    vi) SELECT AVG(BASIC+ ALLOWANCE), QUALF FROM SALARY S1, STAFF S2

    WHERE S1.ID=S2.ID GROUP(QUALF)

    vi) SELECT DISTINCT QUALF FROM STAFF vii) SELECT NAME, BASIC+ALLOWANCE FROM STAFF S, SALARY SA

    WHERE S.ID=SA.ID AND YEAR(DOJ)9000;

    25. Write key feature of MySql (Any Four). Write Classification of Sql Statements

    26. Write any four important data type with example .

    27. Write uses of comment in MySql with an example

    28. Describe Following Comamnd with proper example

    i. Desc

    ii. Distinct

    iii. Where clause

    iv. Create Table

    29. Describe Relation & Logical Operatorsin SQL .Describe with example

    30. Differentiate beween IN and BETWEEN Operator with example .

    31. What is Order By Clause.Define with example.

  • 15

    MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

    15

    32. Describe Following Function with proper example

    i. Char

    ii. Concat

    iii. Lower/Upper

    iv. Substr

    v. Rtrim

    vi. Ltrim

    vii. Trim

    viii. Instr

    ix. Left

    x. Length

    33. Describe Following function with proper example

    i. Mod

    ii. Power/pow

    iii. Round

    iv. Truncate

    v. Sign

    vi. Sqrt

    vii. Month

    viii. Dayofmonth

    34. What is a Primary Key Constraint? How many Primary Key Constraints can you

    define for a table?

    What is a Foreign Key Constraint? Can you define multiple foreign key constraints

    for a table?

    35. What is relation? Define the relational data model.

    36. What is foreign key and Candidate Key?

    37. What is single row function?

    38. What is the purpose of distinct clause? Explain with example.

    39. What is the use of AS keyword with SELECT statement?

    40. Difference between delete and drop.

    41. What is Join in Mysql .

    42. What is SQL comments ?

    43. What is the purpose of DISTINCT And COUNT functions ?

    44. How will you remove leading and trailing spaces from the string ?

    45. Write the command to display the system date and time.

    46. What is Difference between update and alter command.

    47. What do you mean by an attribute ? Explain with an Example.

    48. (a) Write SQL commands for following based on given table “COURSE”:-

  • 16

    MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

    16

    i) List names of B.Tech students taken admission through free seat. ii) List those students who have taken admission(DOA) in year 2004. iii) List total no. of students of BCA courses. iv) How many courses are offered to students. v) Name the courses so that the record of course having minimum fee is

    displayed first.

    vi) Remove the records of BCA courses having fees more than 30000. vii) Increment the fees of B.TECH courses of payment seat by 2%. viii) List names of students taken admission through payment seat in year 2010.

    Name Course_Name DOA fees seat

    RAHUL B.Tech 5-MAY-2005 50000 payment

    SUJOY MCA 11-FEB-1998 34000 free

    HARJEET BCA 21-OCT-2004 24000 free

    JAMAL B.Tech 22-SEP-2004 30000 free

    JOHN BCA 1-JAN-2010 32000 payment

    (b) Give the output of the following SQL commands based on table „COURSE‟:-

    i) Select DAYOFMONTH(DOA) from course;

    ii) SELECT SUBSTR(Name,3,3) FROM course.

    iii) SELECT Name, Course_name FROM course WHERE fees < 50000.

    iv) Select sum(fees) from course where course_name=”BCA”.

    49. In a database there are two tables „Customer‟ and „Bill‟ as shown below:

    (i) (ii) What is the cardinality of table Customer and Degree of Relation of table Bill?

    (iii) (iv) Which column in the 'Bill' table is the foreign key?

    (v) (vi) Which column in the „Customer‟ table can be made as UNIQUE KEY ?

  • 17

    MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

    17

    50. Consider the tables HANDSETS and CUSTOMER given below:

    With reference to these tables, Write commands in SQL for (i) and (ii)

    and output for (iii) & (iv) below:

    (i) Display the CustNo, CustAddress and corresponding SetName for each customer.

    (ii) Display the Customer Details for each customer who uses a Nokia

    handset.

    (iii) Select SetNo, SetName from Handsets, customer

    where SetNo = SetCode and CustAddress = 'Delhi';

    (iv) Select TouchScreen, count(*) from Handsets where phonecost >=5000

    group by TouchScreen;

    51. Write SQL command to create a following table “TEACHER”:-

    Field Datatype Size

    Teacher_ID Varchar 10

    Teacher_name Varchar 20

    Age int 3

    Dept Varchar 10

    DOJ Date -----

    Salary float 7,2

    Gender Varchar 1

    52.

    (a)

    Write SQL commands for the following on the basis of table TEACHER:-

    Teacher_ID Teacher_Name Age Dept DOJ Salary Gender

    1 Jugal 24 Maths 10/01/97 12,000 M

    2 Shamila 21 Maths 24/03/98 22,000 F

    3 Sangeeta 45 Science 01/07/97 40,000 F

    4 Rakesh 28 Science 05/09/97 25,000 M

    5 shalakha 53 Computer 31/07/97 20,000 F

    (i) List the details of teachers of science and maths dept.

    (ii) Insert a new row in table TEACHER with following data:-

    [“T005”, “RAJARAM”,26,”MATHS”,{13/05/95},13500,”M”]

  • 18

    MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

    18

    (iii) Remove the records of teachers who have not been assigned any dept. yet.

    (iv) Display name, salary and age of female teachers starting from senior-most teacher.

    (v) How many teachers are working in computer dept.

    (vi) How many departments are there in a school?

    (vii) List those teachers who have joined the school in the year 1997.

    (viii) Increase the salary of female teachers of maths dept. by 5%.

    (ix) List those teachers who have 5 letters name.

    (x) Display the maximum salary of male teachers aged above 25.

    (b) Give the output of the following commands:-

    i) select avg(sal) from teacher where gender=‟f‟ and sal>20000;

    ii) select distinct dept from teacher where gender=‟m‟ or gender =‟f‟;

    iii) select teacher_name, salary from teacher where DOJ>”1997/05/10”;

    iv) select count(*) from teacher where gender=”f” and dept=”science”;

    c) i) SELECT MOD(Age,6) FROM teacher where salary

  • 19

    MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

    19

    (ii) Display the book name and total cost(Price*Qty) of each book in stock.

    (iii) To increase the price of all books of First PB by Rs. 50.

    (iv) To insert a new row in the table BOOK having the following data :

    {“C0002”,”Informatics Practices”,”S.Arora”,”TDH”,150.00,”Text”,8}

    (v) List those books by „TDH‟ whose name starts with „T‟.

    (vi) Remove the records of those books that are “TEXT” type and published by “EPB”.

    Give the output of the following queries based on the above table :

    (vii) SELECT DISTINCT Publishers FROM Book.

    (viii) SELECT RIGHT(Author_Name,6) FROM Book WHERE Quantity >5.

    (ix) SELECT Book_Name, Author_Name FROM Book WHERE Price

  • 20

    MOHIT TANDON www.mscclucknow.com 9839013528, 9838453834

    20

    (ii) SELECT MOD(25,6)+10;

    (iii) SELECT LENGTH(“RAMESH SHARMA);

    56. Find the outputs- 5×1=5 (a) select round(20009,111,-2);

    (b) select sqrt(81),sqrt(17),sqrt(-1);

    (c) select mid(„abs public school‟ ,11,8), trim(leading „!‟ from „!!!!!welcome!!!!!‟);

    (d) select substr( rtrim(„india is great „),3,9);

    (e) select concat(upper („xihum‟), lower(‟xisc‟), upper(substr(„xicom‟,2,3)));

    57. Write SQL commands for the statements ( i ) to ( vi) and give outputs for SQL

    Queries (vii) to (x) Table: CLUB 10

    GCode GameName Number Fees StartingDate

    101 Carom Board 2 5000 2004-01-23

    102 Badminton 2 12000 2003-12-12

    103 Table Tennis 4 8000 2004-02-14

    104 Chess 2 9000 2004-01-01

    105 Lawn Tennis 4 25000 2004-03-19

    (i) To display the name of all games with their Gcodes.

    (ii) To display details of those games which are having Fees more than 7000.

    (iii)To display the content of the CLUB table in descending order of startDate.

    (iv) To delete the record of all GameNames.

    (v) List the minimum and maximum fees from CLUB.

    (vi) SELECT SUM(Fees) from CLUB;

    (vii) SELECT MAX(StartDate),MIN(StartDate) FROM CLUB;

    (viii) SELECT COUNT(*) from CLUB;

    (ix) SELECT FEES+100 from CLUB where GCode=105;

    (x) SELECT FEES-50 from CLUB where GCode=104;