ch12SQL Commands

Download as pdf or txt
Download as pdf or txt
You are on page 1of 8

SAINIK SCHOOL GOPALGANJ

SUB: COMPUTER SCIENCE


CLASS - XII
ASSIGNMENT

Lesson: 12: SQL Commands

A. (Q1 to Q20) There are four options against each question. Choose the
option which you consider the most appropriate as your answer.

1. The statement in SQL which allows changing the definition of a table is


(A) Alter.
(B) Update.
(C) Create.
(D) select.
2. The statement in SQL which allows changing the definition of a table is
(A) Alter.
(B) Update.
(C) Create.
(D) select.
3. Key to represent relationship between tables is called
(A) Primary key
(B) Secondary Key
(C) Foreign Key
(D) None of these
4. _______ produces the relation that has attributes of R1 and R2
(A) Cartesian product
(B) Difference
(C) Intersection
(D) Product
5. It is better to use files than a DBMS when there are
(A) Stringent real-time requirements.
(B) Multiple users wish to access the data.
(C) Complex relationships among data.
(D) All of the above.
6. The conceptual model is
(A) dependent on hardware.
(B) dependent on software.
(C) dependent on both hardware and software .
(D) independent of both hardware and software.
7. What is a relationship called when it is maintained between two entities?
(A) Unary
(B) Binary

1
(C) Ternary
(D) Quaternary
8. Which of the following operation is used if we are interested in only certain
columns of a table?
(A) PROJECTION
(B) SELECTION
(C) UNION
(D) JOIN
9 Which of the following is a valid SQL type?
(A) CHARACTER
(B) NUMERIC
(C) FLOAT
(D) All of the above
10. The RDBMS terminology for a row is
(A) tuple.
(B) relation.
(C) attribute.
(D) degree.
11. Create table is
a) DDL Command
b) DML command
c) DCL Command
d) None of these

12. Which operator performs range seraching?


a) Like
b) Between
c) IN
d) None of these

13. Which operator test column for absence of data?


a) is NULL
b) =NULL
c) EXISTS
d) None of these

14. Which function gives cardinality?


a) count(column_name)
b) count(*)
c) min(column_name)
d) None of these

15. Which one is not a DDL COMMAND?


a) Create

2
b) Alter
c) Drop
d) None of these

16. Which one is not a DML COMMAND?


a) Update
b) Select
c) Delete
d) None of these

17. Which one is a DML COMMAND?


a) Update
b) Create
c) Alter
d) None of these

18. Which one is correct SQL command?


a) select name and address from admin;
b) select name, address from admin;
c) select name, address where name= “abc”;
d) None of these

19. Which one is correct SQL command from selecting the name of employees from
emp table where salary is 10000 and 20000?
a) select name from emp where salary =10000 and 20000;
b) select name from emp where salary between10000 and 20000;
c) select name from emp where salary IN(10000,20000);
d) None of these

20. Select the right statement for inserting record in student table
a) INSERT student values(.................)
b) INSERT values(................)
c) INSERT INTO student values (....................)
d) INSERT values INTO student (..................)

(C) Unique key (D) Foreign key

B. Short Answer Questions:

a) What are DDL and DML?


b) Write an SQL command to increase the rating of all customers by 10% from
customer table.
c) Write an SQL command to delete the record of roll no 1 from student table?

3
d) Write an SQL command to display the number of records from student table.
e) Write an SQL command to display the list of students from student table in
ascending order to their name.

C. Long Answer Questions:

1. Consider the following tables CARDEN and CUSTOMER and answer (b) and (c)
parts .

(b) Write SQL commands for the following statements:


(i) To display the names of all silver colored Cars.
(ii) To display name of car, make and capacity of cars in descending order of their sitting
capacity.
(iii) To display name of car ,color, cname with their matching ccode
(iv) To display the customer name and the corresponding name of the cars hired by
them.

(c) Give the output of the following SOL queries:


(i) SELECT COUNT (DISTINCT Make) FROM CARDEN;
(ii) SELECT MAX (Charges), MIN (Charges) FROM CARDEN;
(iii) SELECT COUNT (*), Make FROM CARDEN;
(iv) SELECT CarName FROM CARDEN WHE~ Capacity = 4;

2. Study the following tables EMPLOYEE and SALARY and write SQL commands for
the question (i) to (iv) and give output for SQL queries (v) to (viii)

4
Relation: Employee

ID NAME DOJ DEPT SEX QUALF

101 Siddharth 12/01/02 Sales M MBA

104 Raghav 8/05/88 Finance M CA

107 Naman 14/05/88 Research M MTECH

114 Nupur 1/02/03 Sales F MBA

109 Janvi 18/7/04 Finance F ICWA

105 Rama 14/4/07 Research M BTECH

117 Jace 27/6/87 Sales F MTECH

111 Binoy 12/1/90 Finance M CA

130 Samuel 7/3/99 Sales M MBA

187 Ragini 12/12/02 Research F BTECH

Relation: SALARY

ID SALARY ALLOWANCE COMM_PERC

101 15240 5400 3

104 23000 1452 4

107 14870 2451 3

114 21000 3451 14

109 24500 1452 10

105 17000 1250 2

117 12450 1400 3

111 13541 3652 9

5
i. (i) Display the name of all CA’s who are working in sales department.
ii. (ii) Display the number of employee in finance department.
iii. (iii) Increase the salary of all female employee by 2000.
iv. (iv) Display the average salary given to the employee in each department (ID).
v.
vi. (v) SELECT DEPT, COUNT(*) FROM EMPLOYEE GROUP BY DEPT
vii. (vi) SELECT MIN(SALARY+ ALLOWANCE) FROM SALARY
viii. (vii) SELECT DISTINCT QUALF FROM Employee
(viii) SELECT NAME FROM EMPLOYEE WHERE YEAR(DOJ)<2002

3. Consider the following tables Consignor and Consignee. Write SQL commands for
the statements (i) to (iv) and give outputs for SQL queries (v) to (viii).

TABLE : CONSIGNOR

CnorlD CnorName CnorAddress City


ND01 R Singhal 24, ABC Enclave New Delhi
ND02 Amit Kumar 123, Palm Avenue New Delhi

MU15 R Kohli 5/A, South Street Mumbai


S
MU50 Kaur 27-K, Westend Mumbai

TABLE : CONSIGNEE

CneelD CnorlD CneeName CneeAddress CneeCity


Rahul
MU05 ND01 Kishore 5, Park Avenue Mumbai
16/J, Moore New
ND08 ND02 P Dhingra Enclave Delhi
2A, Central
KO19 MU15 A P Roy Avenue Kolkata
MU32 ND02 S Mittal P245, AB Colony Mumbai
13, Block D, A New
ND48 MU50 B P Jain Vihar Delhi

(i) To display the names of all Consignors from Mumbai.’


(ii) To display the CneelD, CnorName, CnorAddress, CneeName, CneeAddress for
every Consignee.
(iii) To display consignee details in ascending order of CneeName.
(iv) To display number of consignors from each city,

(v) SELECT DISTINCT City FROM CONSIGNEE;

6
(vi) SELECT A.CnorName, B.CneeName
FROM Consignor A, Consignee B
WHERE A.CnorID = B.CnorlD AND B.CneeCity = ‘Mumbai’;

(vii) SELECT CneeName, CneeAddress FROM Consignee


WHERE CneeCity NOT IN (‘Mumbai’, ‘Kolkata’);

(viii) SELECT CneelD, CneeName


FROM Consignee
WHERE CnorID=’MU15' OR CnorID=’ND01';

4. Consider the following EMPLOYEE tables. Write SQL queries for (i) to (vi) and find
outputs for SQL queries (vii) to (x).

Table : EMPLOYEE

ENO NAME DOJ DOB GENDER DCODE


1001 George K 2013-09-02 1991-09-01 MALE D01
1002 RymaSen 2012-12-11 1990-12-15 FEMALE D03
1003 Mohitesh 2013-02-03 1987-09-04 MALE D05
1007 Anil Jha 2014-01-17 1984-10-19 MALE D04
1004 Manila Sahai 2012-12-09 1986-11-14 FEMALE D01
1005 R SAHAY 2013-11-18 1987-03-31 MALE D02
1006 Jaya Priya 2014-06-09 1985-06-23 FEMALE D05

(i) To display Eno, Name, Gender from the table EMPLOYEE in ascending order of
Eno.
(ii) To display the Name of all the MALE employees from the table EMPLOYEE.
(iii) To display the Eno and Name of those employees from the table EMPLOYEE who
are born between ‘1987-01-01’ and ‘1991-12-01’.
(iv) To count and display FEMALE employees who have joined after ‘1986-01-01’.
(v) To display the details of those employees from employee table whose date of
Joining is in the year 2002
(vi) To count and display the unique DCODE from the table employees

(vii) SELECT COUNT(*)FROM EMPLOYEE WHERE GENDER LIKE ‘ FEMALE’;


(viii) SELECT DISTINCT DCODE FROM EMPLOYEE;
(ix) SELECT NAME,DOJ FROM EMPLOYEE ENO<1003;
(x) SELECT MAX(DOJ), MIN(DOB) FROM EMPLOYEE;

5. Write the SQL commands for (i) to (iv) on the basis of the table HOSPITAL.

7
TABLE: HOSPITAL

No. Name Age Department Dateofadm Charges Sex

1 Sandeep 65 Surgery 20/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 20/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 Gynecology 22/02/98 300 F

9 Kush 19 Cardiology 22/02/98 800 M

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

I. To show all information about the patients of cardiology department.


II. To list the name of female patients who are in orthopedic department.
III. To list names of all patients with their date of admission in ascending
order.
IV. The display Patient’s Name, charges, age for male patients only.

Write output for the following SQL commands for Hospital Table.

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 age>36;

--------------

You might also like