0% found this document useful (0 votes)
1K views

12 Assignment SQL

This document contains 4 questions about SQL commands and database tables. Question 1 has subparts asking for SQL queries on a HOSPITAL table including counting, sorting, aggregating, and inserting data. Question 2 is similar but uses a STUDENT table. Question 3 differentiates SQL commands, includes more queries on a GRADUATE table, and a join. Question 4 includes additional SQL queries on a SPORTS table.

Uploaded by

Vansh Chaudhary
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

12 Assignment SQL

This document contains 4 questions about SQL commands and database tables. Question 1 has subparts asking for SQL queries on a HOSPITAL table including counting, sorting, aggregating, and inserting data. Question 2 is similar but uses a STUDENT table. Question 3 differentiates SQL commands, includes more queries on a GRADUATE table, and a join. Question 4 includes additional SQL queries on a SPORTS table.

Uploaded by

Vansh Chaudhary
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

12th Assignment SQL

Q1. (a)What is the need for Databases ? Define tables and views. 2
(B) Write the SQL commands for (b) to (g ) and write the outputs for (h) on the basis of the table
HOSPITAL :
TABLE : HOSPITAL
No. Name Age Department Dateofadm Charges Sex
1 Sandeep 65 Surgery 23/02/98 300 M
2 Ravina 24 Orthopaedic 20/01/98 200 F
3 Karan 45 Orthopaedic 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 Ankita 29 Cardiology 20/02/98 800 F
8 Zareen 45 Gynaecology 22/02/98 300 F
9 Kush 19 Cardiology 13/01/98 800 M
10 Shailya 31 Nuclear Medicine 19/02/98 400 M
(b) To show all information about the patients of cardiology department. 1
(c) To list the name of female patients who are in orthopaedic department. 1
(d) To list names of all patients with their date of admission in ascending order. 1
(e) The display Patient’s Name, charges, age for male patients only. 1
(f) To count the number of patients with age>20. 1
(g ) To insert a new row in the HOSPITAL table with the following data : 1
11, ‘Mustafa’, 37, ‘ENT’, {25/02/98}, 250, ‘M’
(h) Give the output of following SQL statements : 2
(i) Select COUNT (DISTINCT Charges) from HOSPITAL;
(ii) Select MIN (Age) from HOSPITAL where Sex = ‘M’;
(iii) Select SUM(Charges) from HOSPITAL where Sex = ‘F’;
(iv) Select AVG (Charges) from HOSPITAL where Dateofadm < {12/02/98};

Q.2 (a) What are features of databases ? 2


Given the following Student relation :
Table :Student

No. Name Age Department Dateofadm Fee Sex


1. Pankaj 24 Computer 10/01/97 120 M
2. Shalini 21 History 24/03/98 200 F
3. Sanjay 22 Hindi 12/12/96 300 M
4. Sudha 25 History 01/07/99 400 F
5. Rakesh 22 Hindi 05/09/97 250 M
6. Shakeel 30 History 27/06/98 300 M
7. Surya 34 Computer 25/02/97 210 M
8 Shikha 23 Hindi 31/07/97 200 F
Write SQL commands for (b) to (g) and write output for (h).
(b) To show all information about the students of History department. 1
(c) To list the names of female students who are in Hindi department. 1
(d) To list the names of all students with their date of admission in ascending order. 1
(e) To display student’s Name, Fee, Age for male students only. 1
(f) To count the number of students with Age > 23. 1
(g) To insert a new row in the STUDENT table with the following data :
9, “Zaheer”, 36, “Computer”, {12/03/97}, 230, “M” 1
(h) Give the output of the following SQL statement : 2
(i) Select COUNT(distinct department) from STUDENT;
(ii) Select MAX(Age) from STUDENT where SEX = “F”;
(iii) Select AVG(Fee) from STUDENT where SEX = “M”;
(iv) Select SUM(Fee) from STUDENT where Dateofadm < {01/01/98};

Q3. (a) Differentiate between SQL commands DROP TABLE and Delete Table. 2

Write SQL commands for (b) to (f) and write the outputs for (g) on the basis of table GRADUATE :
Table : GRADUATE
SNO NAME STIPEND SUBJECT AVERAGE DIV
1 KARAN 400 PHYSICS 68 1
2 DIVAKAR 450 COMPUTER SC 68 1
3 DIVYA 300 CHEMISTRY 62 2
4 ARUN 350 PHYSICS 63 1
5 SABINA 500 MATHEMATICS 70 1
6 JOHN 400 CHEMISTRY 55 2
7 ROBERT 250 PHYSICS 64 1
8 RUBINA 450 MATHEMATICS 68 1
9 VIKAS 500 COMPUTER SC 62 1
10 MOHAN 300 MATHEMATIC 57 2
(b) List the names of those students who have obtained Div 1 sorted by NAME. 1
(c) Display the report, listing NAME, STIPEND, SUBJECT and amount of stipend received in a year
assuming that the STIPEND is paid every month. 1
(d) To count the number of students who are either PHYSICS or COMPUTER SC graduates. 1
(e) To insert a new row in the GRADUATE table : 1
11, “KAJOL”, 300, “COMPUTER SC”, 75, 1
(f) Give the output of following SQL statement based on table GRADUATE : 2
(i) Select MIN(AVERAGE ) from GRADUATE where SUBJECT= “PHYSICS”;
(ii) Select SUM(STIPEND) from GRADUATE where DIV = 2;
(iii) Select AVG(STIPEND) fromGRADUATE where AVERAGE >= 65;
(iv) Select COUNT(DISTINCT SUBJECT) from GRADUATE;
(g) Assume that there is one more table GUIDE in the database as shown below : 2
Table : GUIDE
MAINAREA ADVISOR
PHYSICS VINOD
COMPUTER SC ALOK
CHEMISTRY RAJAN
MATHEMATICS MAHESH
What will be the output of the following query :
SELECT NAME, ADVISOR
FROM GRADUATE, GUIDE
WHERE SUBJECT = MAINAREA;
Q4. (a) When is a Relation, Cardinality, Degree , View ? 2
(b) Write SQL commands for (i) to (vii) on the basis of the table SPORTS
Table : SPORTS
Student No. Class Name Game1 Grade Game2 Grade1
10 7 Sameer Cricket B Swimming A
11 8 Sujit Tennis A Skating C
12 7 Kamal Swimming B Footbal B
13 7 Veena Tennis C Tennis A
14 9 Archana Basketball A Cricket A
15 10 Arpit Cricket A Athletics C
Display the names of the students who have grade ‘C’ in either Game1 or Game2 or both. 1
(i)
Display the number of students getting grade ‘A’ in Cricket.
(ii) 1
(iii)
Display the names of the students who have same game for both Game1 and Game2. 1
(iv)Display the games taken up by the students, whose name starts with ‘A’. 1
Add a new column named “Marks”.
(v) 1
Assign a value 200 for Marks for all those who are getting grade ‘B’ or grade ‘A’ in both Game1
(vi)
and Game2. 1
(vii) Arrange the whole table in the alphabetical order of Name. 1
(c) Explain Cartesian product of two relations. 1

Q5. (a) Differentiate between Data Definition Language and Data Manipulation Language. 2
Given the following Teacher relation : Write SQL command for question (b) to (h).
No Name Department Dateofjoining Salary Sex
1. Raja Computer 21/05/98 8000 M
2. Sangita History 21/05/97 9000 F
3. Ritu Sociology 29/08/98 8000 F
4. Kumar Linguistics 13/06/96 10000 M
5. Venkatraman History 31/10/99 8000 M
6. Sidhu Computer 21/05/86 14000 M
7. Aishwarya Sociology 11/01/98 12000 F
(b) To select all the information of teacher in computer department. 1
(c) To list the name of female teachers in History department. 1
(d) To list all names of teachers with date of admission in ascending order. 1
(e) To display Teacher’s name, Department, and Salary of female teacher. 1
(f) To count the number of items whose salary is less than 10,000. 1
(g) To insert a new record in the Teacher table with the following data : 1
8, “Mersha”, “Computer”, {1/1/2000}, 12000, “M”.
(h) Give the output of the following SQL command : 2
(i) SELECT MIN(DISTINCT Salary) FROM Teacher
(ii) SELECT MIN(Salary) FROM Teacher WHERE Sex = “M”
(iii) SELECT SUM(Salary) FROM Teacher WHERE Department = “History”
(iv) SELECT AVG(Salary) FROM Teacher WHERE Dateofjoining < {1/1/98}
Q6 (a) What is a primary key in a table ? Define concept of Keys. 2
NOTE : Write SQL commands for (b) to (g) and write the outputs for (h) on the basis of tables
INTERIORS and NEWONES :
Table : INTERIORS
NO ITEMNAME TYPE DATEOFSTOCK PRICE DISCOUNT
1 Red rose Double Bed 23/02/02 32000 15
2 Soft touch Baby cot 20/01/02 9000 10
3 Jerry’s home Baby cot 19/02/02 8500 10
4 Rough wood Office Table 01/01/02 20000 20
5 Comfort zone Double Bed 12/01/02 15000 20
6 Jerry look Baby cot 24/02/02 7000 19
7 Lion king Office Table 20/02/02 16000 20
8 Royal tiger Sofa 22/02/02 30000 25
9 Park sitting Sofa 13/12/01 9000 15
10 Dine Paradise Dining Table 19/02/02 11000 15
11 White Wood Double Bed 23/03/03 20000 20
12 James 007 Sofa 20/02/03 15000 15
13 Tom look Baby cot 21/02/03 7000 10

(b) To show all information about the Sofa from the INTERIORS table. 1
(c) To list the ITEMNAME which are priced at more than 10000 from the INTERIORS table. 1
(d) To list ITEMNAME and TYPE of those items, in which DATEOFSTOCK is before 22/01/02 from the
INTERIORS table in descending order of ITEMNAME. 1
(e) To display ITEMNAME and DATEOFSTOCK of those items, in which the discount percentage is
more than 15 from INTERIORS table. 1
(f ) To count the number of items, whose type is “Double Bed” from INTERIORS table. 1
(g) To insert a new row in the NEWONES table with the following data : 1
14, “True Indian”, “Office Table”, {28/03/03},15000, 20
(h) Give the output of following SQL statement : 2

NOTE : Outputs of the below mentioned queries should be based on original data given in both the
tables i.e., without considering the insertion done in (g) part of this question :
(i) Select COUNT(distinct TYPE) from INTERIORS;
(ii) Select AVG(DISCOUNT) from INTERIORS where TYPE = “Baby cot”;
(iii) Select SUM(Price) from INTERIORS where DATEOFSTOCK<{12/02/02};
Q7. (a) What do you understand by RDBMS ? what is Relation ? 2
Given the following tables for a database LIBRARY
Table : Books
Book_Id Book_Name Author_Name Publishers Price Type Quantity
F0001 The Tears William Hopkins First Publ 750 Fiction 10
F0002 Thunderbolts Anna Roberts First Publ. 700 Fictioin 5
T0001 My First C++ Brain & Brooke EPB 250 Text 10
T0002 C++ Brainworks A.W. Rossaine TDH 325 Text 5
C0001 Fast Cook Lata Kapoor EPB 350 Cookery 8
Table : Issued
Book_Id Quantity_Issued
F0001 3
T0001 1
C0001 5
Write SQL queries for (b) to (g) and output of (h):
(b) To show Book name, Author name and Price of books of EPB. Publishers. 1
(c) To list the names from books of Fiction type . 1
(d) To display the names and price of the books in descending order of their price. 1
(e) To increase the price of all books of First Publ. Publishers by 50. 1
(f ) To display the Book_Id, Book_Name and Quantity_Issued for all books which have been issued.
(The query will require contents from both the tables.) 1
(g) To insert a new row in the table Issued having the following data : 1
“F0002”, 4
(h) Give the output of the following queries based on the above tables : 2
(i) SELECT COUNT(DISTINCT Publishers) FROM Books; (ii)
SELECT SUM(Price) FROM Books WHERE Quantity > 5;
(iii) SELECT Book_Name, Author_Name FROM Books WHERE Price < 500;
(iv) SELECT COUNT (*) FROM Books;
8.
a) What do you understand by the following in a relation database : 2

i) Candidate Key ii) Project Operation.

b) Consider the following tables BOOKINGS and PACKAGE and write SQL

commands for (i) to (iv) and outputs for (v) and (vi). 6

BOOKINGS

Pcode Tourist Name Agency No_of_persons Tdate

P5 Raghavendra Voyager 2 23-dec-10

P2 Hardep Pristine 4 12-jan-11

P5 Shazia Go Now 6 25-dec-10

P6 Lizza Pristine 2 28-dec-10

P3 Diana Voyager 4 19-mar-11


P6 Harshal Go Now 4 21-mar-11

P1 Rajiv Khanna Travels 12 12-apr-11

P1 Veena Sethi Voyager 5 01-apr-11

PACKAGE

Pcode Pname Per_Person_amt

P1 Kerala 20000

P2 Malaysia 35000

P3 Goa 56525

P4 Manali 15000

P5 Simla 12000

P6 Singapore 75450

a) Display the name of all the tourists, their travel dates, names of the places they are traveling to and
the total amount to be payed by each tourist.
b) Display the name of the agencies from the BOOKING table.
c) Arrange the contents of the table BOOKING in ascending order of travel date.
d) Display the maximum no_of_persons traveling of each travel agency.
e) SELECT Tourist Name, Agency, Pname from BOOKINGS, PACKAGE where BOOKINGS.Pcode =
PACKAGES.Pcode and Per_person_amt>3500;
SELECT Agency, sum(No_of_persons) from BOOKING group by agency having
sum(No_of_persons)>10;

You might also like