0% found this document useful (0 votes)
25 views

sql_command_test_1

The document contains a series of SQL commands and queries related to various tables such as Bank, Student, and Transaction. It includes tasks like creating tables, displaying data, filtering records based on conditions, and performing calculations. The document also discusses RDBMS operations and cardinality and degree of tables.

Uploaded by

tutor nag
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
25 views

sql_command_test_1

The document contains a series of SQL commands and queries related to various tables such as Bank, Student, and Transaction. It includes tasks like creating tables, displaying data, filtering records based on conditions, and performing calculations. The document also discusses RDBMS operations and cardinality and degree of tables.

Uploaded by

tutor nag
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Roll No : Name of School : Time - MM- 41

Date : Name of Assessment :


Subject :
Class :

1 Consider the following table Bank.Table: Bank 3


AccNo Cust_name FD_Amount Months Int_Rate FD_Date
1001 Arti Gupta 30000 36 6.00 2018-07-01
1002 Dilip Lal 50000 48 6.75 2018-03-22
1003 Navin Gupta 30000 36 NULL 2018-03-01
1004 D.P. Yadav 80000 60 8.25 2017-06-12
1005 Jyoti Sharma 20000 36 6.50 2017-01-31
1006 Rakesh Kumar 70000 60 8.25 2018-06-15
1007 K.D. Singh 50000 48 NULL 2018-07-05
1008 Anjali Sharma 60000 48 6.75 2017-04-02
1009 Swati Garg 40000 42 6.50 2018-06-15
1010 Rupinder Kaur 25000 36 6.50 2018-09-27
Write SQL commands for the statements (a) to (g) on the table BANK
(a) To create the table Bank (Primary Key: AccNo)
(b) Display the structure of the table Bank.
(c) Display the details of all the bank.
(d) Display the AccNo, Cust_Name, and FD_Amount.
(e) Display the details of all the FD’s having maturity time is less than 40 months.
(f) Display the AccNo and FD amount which started before 01-04-2018.
(g) Display details of all FD whose rate of interest are NULL.
2 Consider the following table Bank. 3
Table: Bank
AccNo Cust_name FD_Amount Months Int_Rate FD_Date
1001 Arti Gupta 30000 36 6.00 2018-07-01
1002 Dilip Lal 50000 48 6.75 2018-03-22
1003 Navin Gupta 30000 36 NULL 2018-03-01
1004 D.P. Yadav 80000 60 8.25 2017-06-12
1005 Jyoti Sharma 20000 36 6.50 2017-01-31
1006 Rakesh Kumar 70000 60 8.25 2018-06-15
1007 K.D. Singh 50000 48 NULL 2018-07-05
1008 Anjali Sharma 60000 48 6.75 2017-04-02
1009 Swati Garg 40000 42 6.50 2018-06-15
1010 Rupinder Kaur 25000 36 6.50 2018-09-27
Write SQL commands for the statements (a) to (g) on the table BANK
(a) Display details of all the FD whose rate of interest is NOT NULL.
(b) Display amounts of various FD from the table Bank. An FD Amount should
appear only once.
(c) Display the number of months of various loans from the table Bank. A month
should appear only once.
(d) Display the Customer Name and FD Amount for all the Bank which do not have a
number of months is 36.
(e) Display the Customer Name and FD Amount for which the FD amount is less than
500000 or int_rate is more than 7.
(f) Display the details of all FD which started in the year 2018.
(g) Display the details of all FD whose FD_Amount is in the range 40000 to 50000.
3 Consider the following table Bank. 3
Table: Bank
AccNo Cust_name FD_Amount Months Int_Rate FD_Date
1001 Arti Gupta 30000 36 6.00 2018-07-01
1002 Dilip Lal 50000 48 6.75 2018-03-22
1003 Navin Gupta 30000 36 NULL 2018-03-01
1004 D.P. Yadav 80000 60 8.25 2017-06-12
1005 Jyoti Sharma 20000 36 6.50 2017-01-31
1006 Rakesh Kumar 70000 60 8.25 2018-06-15
1007 K.D. Singh 50000 48 NULL 2018-07-05
1008 Anjali Sharma 60000 48 6.75 2017-04-02
1009 Swati Garg 40000 42 6.50 2018-06-15
1010 Rupinder Kaur 25000 36 6.50 2018-09-27
Write SQL commands for the statements (a) to (h) on the table Bank
(a) Display the details of all FD whose rate of interest is in the range 6% to 7%.
(b) Display the Customer Name and FD Amount for all the loans for which the
number of Months is 24, 36, or 48(using IN operator).
(c) Display the Account Number, Customer Name and FD Amount for all the FD for
which the Customer Name
ends with “Sharma”.
(d) Delete the records of “Rupinder Kaur”.
(e) Add another column Maturity_Amt of type Integer in the Bank table.
(f) To find the average FD amount. Label the column as “Average FD Amount”.
(g) To find the total FD amount which started in the year 2018?
(h) Update Maturity Amount of all bank customers.
a. Maturity Amount = (FD_Amount*Months* Int_rate)/(12*100)

4 Consider the following table Student & Stream. 3


Table: Student
Admno Sname Class Sec Fee Mobile Area S_ID
1001 RAMESH XII A 2500 987654321 Madipur 10
1078 KRISHNA XII B 2400 999911111 Jawala Heri 30
1006 FARDEEN XII C 2600 987654321 Paschim Puri 40
1004 SUBHAM XII A 2500 963025874 Madipur 20
1029 KRITIKA XI C 2700 987456210 Madipur 30
1008 SAMEEKSHA XII A 2450 987123456 Mangol Puri 20
1025 SALMA XII B 2580 998877445 Madipur 30
1036 AMANDEEP XII B 2600 999333555 Khyala 40
1037 TEJAS XI C 2650 987951357 Paschim Puri 40
1029 HIMANSHU XII A 2750 951369874 Jawala Heri 10
Table : Stream
S_ID Stream_name
10 MEDILCAL
20 NON MEDICAL
COMMERCE WITH
30
MATH
40 COMMERCE WITH IP
50 HUMANITIES
Write SQL commands for the statements (a) to (h) on the above table: Student and
Stream
(a) Identify Primary Keys and Foreign Key in the table student and primary key in
Stream table given above.
(b) Display stream id and stream-wise total fee collected.
(c) Count no of students from each area.
(d) Display all the student details those who belongs to Madipur Area.
(e) Increase the fees of all students by10%.
(f) Display unique area from the student table.
(g) Display details of those students whose area contains ‘Puri’.
(h) Display the information of those students who are in class XII and section is
either B or C.
5 Consider the following table Student & Stream. 3
Table: Student
Admno Sname Class Sec Fee Mobile Area S_ID
1001 RAMESH XII A 2500 987654321 Madipur 10
1078 KRISHNA XII B 2400 999911111 Jawala Heri 30
1006 FARDEEN XII C 2600 987654321 Paschim Puri 40
1004 SUBHAM XII A 2500 963025874 Madipur 20
1029 KRITIKA XI C 2700 987456210 Madipur 30
1008 SAMEEKSHA XII A 2450 987123456 Mangol Puri 20
1025 SALMA XII B 2580 998877445 Madipur 30
1036 AMANDEEP XII B 2600 999333555 Khyala 40
1037 TEJAS XI C 2650 987951357 Paschim Puri 40
1029 HIMANSHU XII A 2750 951369874 Jawala Heri 10
Table : Stream
S_ID Stream_name
10 MEDILCAL
20 NON MEDICAL
COMMERCE WITH
30
MATH
40 COMMERCE WITH IP
50 HUMANITIES
Write SQL commands for the statements (a) to (h) on the table: Student and Stream
(a) Display class and total fee collected from each class.
(b) Display admission no, students name and stream name.
(c) Display all the student details who have taken Commerce Stream.
(d) Count number of students who have opted for HUMANITIES stream.
(e) Display information of commerce with ip students whose name start with ‘S’.
Arrange the record by admission number.
(f) Display details of all students who are in the MEDICAL stream.
(g) Display total fee of ‘Non-Medical’ Student.
(h) Change the name of the Column Sname to Student_Name.
6 Given the following relation: STUDENT 3
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 the following queries
(a) To show all information about the students of History department.
(b) To list the names of female students who are in Hindi department.
(c) To list the names of all students with their date of admission in ascending order.
(d) To display student’s name, fee, age for male students only.
(e) To count the number of students with Age>23.
7 Write SOL queries for (i) to (iv) and find outputs for SQL queries (v) to (viii) which 3
are based on the tables.
TABLE : CUSTOMERS
NO CNAME ADDRESS
101 Richa jain Delhi
101 Surbhi Sinha Chennai
103 Lisa Thomas Bangalore
104 Imran Ali Delhi
105 Roshan Singh Chennai
TABLE : TRANSACTION
TRNO CNO AMOUNT TYPE DOT
T001 101 1500 Credit 2017-11-23
T002 103 2000 Debit 2017-05-12
T003 102 3000 Credit 2017-06-10
T004 103 12000 Credit 2017-09-12
T004 101 1000 Debit 2017-09-05
(a) To display details of all transactions of TYPE Credit from Table TRANSACTION.
(b) To display the CNO and AMOUNT of all transactions done in the month
September 2017 from the table TRANSACTION.
(c) To display the last date of transaction (DOT) from the table TRANSACTION for
the customer having CNO as 103.
(d) To display all CNO,CNAME and DOT (date of transaction) of those
CUSTOMERS from tables CUSTOMERS and TRANSACTION who have done
transactions more than or equal to 2000.
(e) Select count(*), avg(amount) from transaction where dot>= ‘2017-06-01’;
(f) Select cno, count(*), max (amount) from transaction group by cno having
count(*)> 1;
(g) Select cno, cname from customer where address not in (‘Delhi, ‘Bangalore’);
(h) Select distinct cno from transaction;
8Observe the following tables VIDEO and MEMBER carefully and write the name of the RDBMS 2
operation out of (i) SELECTION (ii) PROJECTION (iii) UNION (iv) CARTESIAN PRODUCT,
which has been used to produce the output FINAL RESULT as shown below, Also, find the Degree
and Cardinality of the final result.
9 Observe the following STUDENTS and EVENTS tables carefully and write the name 2
of the RDBMS operation which will be used to produce the output as shown in LIST ?
Also, find the Degree and Cardinality of the LIST.

10 Observe the following table CANDIDATE carefully and write the name of the 2
RDBMS operation out of
(i) SELECTION (ii) PROJECTION (iii) UNION (iv) CARTESIAN PRODUCT,
which has been used to produce the output as shown in RESULT ? Also, find the
Degree and Cardinality of the RESULT.

11Observe the table ‘Club’ given below: 2


Table: Club
Member_id Member_Name Address Age Fee
M001 Sumit New Delhi 20 2000
M002 Nisha Gurgaon 19 3500
M003 Niharika New Delhi 21 2100
M004 Sachin Faridabad 18 3500
(i) What is the cardinality and degree of the above given table?
(ii) If a new column contact_no has been added and three more members have joined
the club then how these changes will affect the degree and cardinality of the above
given table.
12Consider the table: CLUB as given below: 2
Table: CLUB
MEMBER_ID MEMBER_NAME ADDRESS AGE FEE
M002 NISHA GURGAON 19 3500
M003 NIHARIKA NEW DELHI 21 2100
M004 SACHIN FARIDABAD 18 3500
(a) What is the cardinality and degree of the above given table?
(b) If a new column contact_no has been added and three more members have joined
the club then how these changes will affect the degree and cardinality of the above
given table.
13 Write SQL commands for the following: 2
Table: TEACHER
TID NAME AGE DEPT DATEOFJOIN SAL SEX
T118 Navin 40 Computer 2010-01-10 12000 M
T107 Chetna 37 History 2008-03-24 20000 F
T105 Sandeep 46 Maths 2006-12-12 30000 M
T110 Sangeeta 35 History 2010-07-01 25000 F
T101 Rudransh 42 Maths 2004-09-05 40000 M
T121 Neeraj 38 Physics 2011-04-01 28000 M (i) To
show information about the teachers of the history department.
(ii) To list the names of teachers earning a salary between 20000 and 30000.
(iii) To count the number of male teachers.
(iv) Display gender wise total number of teachers.
(v) To list the name and age of teachers of female teachers in descending order of
date of join.
(vi) Increase the salary by 10% for Maths departments.
( vii) To delete the record of teacher Neeraj.
14 Consider the following table HOSPITAL. 2
Table: HOSPITAL
PNo Name Age Department DateofAdm Charges Sex
1 Mayank 65 Surgery 23/02/2018 600 M
2 Babita 24 ENT 01/01/2019 400 F
3 Kashish 45 Orthopaedic 19/12/2018 400 M
4 Tarun 12 Surgery 01/10/2018 600 M
5 Manisha 36 ENT 12/01/2018 400 F
6 Imran 16 ENT 24/02/2018 400 M
7 Ankita NULL Cardiology 20/08/2018 800 F
8 Zoya 45 Gynecology 22/02/2018 500 F
9 Kush 19 Cardiology 13/01/2019 800 M
10 Shalini 31 Medicine 19/02/2018 300 F
Note: PNo is the primary key in the above table.
Write SQL commands for the statements (a) to (g) on the table HOSPITAL.
(a) To show all the information about the patients of the cardiology department.
(b) To list the names of female patients who are either in the orthopaedic or surgery
department.
(c) To list the name of all the patients with their date of admission in ascending
order.
(d) To display the patient’s name, charges, the age for female patients only.
(e) To count the number of patients with age > 30.
(f) To display various departments.
(g) To display the number of patients in each department.

15 Consider the following table HOSPITAL. 2


Table: HOSPITAL
PNo Name Age Department DateofAdm Charges Sex
1 Mayank 65 Surgery 23/02/2018 600 M
2 Babita 24 ENT 01/01/2019 400 F
3 Kashish 45 Orthopaedic 19/12/2018 400 M
4 Tarun 12 Surgery 01/10/2018 600 M
5 Manisha 36 ENT 12/01/2018 400 F
6 Imran 16 ENT 24/02/2018 400 M
7 Ankita NULL Cardiology 20/08/2018 800 F
8 Zoya 45 Gynecology 22/02/2018 500 F
9 Kush 19 Cardiology 13/01/2019 800 M
10 Shalini 31 Medicine 19/02/2018 300 F
Note: PNo is the primary key in the above table.
Write SQL commands for the statements (a) to (g) on the table HOSPITAL.
(a) To display the details of all the patients whose name starts with the alphabet ‘Z’.
(b) To change the age of the patient Kush to 20.
(c) To increase the charges of all the patients by 5%.
(d) To remove the record of the patient whose Name is Tarun.
(e) To add another column DocName(Doctor Name) of the type varchar in the above
table.
(f) To display patient detail whose age is missing(null).
(g) To decrease the charges by 5% of all the patients admitted to the ENT
department.
16 Write SQL commands for the statements (a) to (h) on the table HOSPITAL 2
(a) To insert a new row in the HOSPITAL table with the following data: 11,’ Kasif’,
37,’ENT’,’2018-02-25’, 300, ’M’.
(b) To set charges to NULL for all the patients in the Surgery department.
(c) To display patient details who are giving charges in the range 300 and 400 (both
inclusive).
(d) To display the details of that patient whose name second character contains ‘a’.
(e) To display total charges of ENT Department.
(f) To display details of the patients who admitted in the year 2019.
(g) To display the structure of the table hospital.
(h) Write the command to create the above table.
17Write outputs for SQL queries (i) to (iii), which are based on the following tables 2
CUSTOMERS and PURCHASES
(i) SELECT COUNT(DISTINCT CITIES) FROM CUSTOMERS;
(ii) SELECT MAX(PUR_DATE) FROM PURCHASES;
(iii) SELECT CNAME, QTY, PUR_DATE FROM CUSTOMERS, PURCHASES
WHERE CUSTOMERS.CNO = PURCHASES.CNO AND QTY IN (10,20);

You might also like