Database Query using Sql Class 12 Informatics Practices Notes and Questions

Notes Class 12 Revision Notes

Please refer to Database Query using Sql Class 12 Informatics Practices notes and questions with solutions below. These revision notes and important examination questions have been prepared based on the latest Informatics Practices books for Class 12. You can go through the questions and solutions below which will help you to get better marks in your examinations.

Class 12 Informatics Practices Database Query using Sql Notes and Questions

TOPIC – DBMS CONCEPTS

Q1. What are different categories of commands in SQL?
Ans.

i) Data Definition Language(DDL)
ii) Data Manipulation Language(DML)
iii) Transaction Control Language(TCL)
iv) Session Control Commands.
v) System Control Commands.

Q2 What do you understand by Candidate Keys in a table? Give a suitable example of Candidate Keys from a table containing some meaningful data
Ans.
Table:Item

Database Query using Sql Class 12 Informatics Practices Notes and Questions

In the above table Item, ItemNo can be a candidate key

Q3 A table Employee contains 5 Rows and 4 Columns and another table PROJECT contains 5 Rows and 3 Columns. How many rows and columns will be there if we obtain Cartesian product of these two tables?
Ans.
Rows = 5 x 5 = 25
Columns = 4 + 3 = 7

Q4 A table ‘Customers’ in a database has 5 columns and no rows in it. What is its degree and cardinality? Later on two columns were deleted from the table and 10 rows added in the table. What will be the new degree and cardinality?
Ans. Degree:- 5 and cardinality:-0.After changes Degree:- 3 and Cardinality :-10

Q5 For the above given database STUDENT-PROJECT, can we perform the following operations?
(a) Insert a student record with missing roll number value.
(b) Insert a student record with missing registration number value.
(c) Insert a project detail without submission-date.
Insert a record with Registration_ID IP-101-19 and ProjectNo 206 in table PROJECT_ASSIGNED.
Ans.
(a) No
(b) Yes
(c) Yes
(d) No, because ProjectNo 206 does not exist in PROJECT table.

Q6 Database __________ which is the logical design of the database, and the database _________ which is snapshot of the data in the database at a given instant in time.
Ans.
Schema, Instance

Q7 STUDENT:

Database Query using Sql Class 12 Informatics Practices Notes and Questions

PROJECT:

Database Query using Sql Class 12 Informatics Practices Notes and Questions

For the given database STUDENT-PROJECT, answer the following:
(a) Name Primary key of each table.
(b) Find Foreign key(s) in table PROJECT-ASSIGNED.
(c) Is there any alternate key in table STUDENT? Give justification for your answer.
Can a user assign duplicate value to the field RollNo of STUDENT table? Justify

Ans.
(a) STUDENT: Roll No
PROJECT: ProjectNo
PROJECT_ASSIGNED: Registration_ID
(b) PROJECTNO
(c) Name can be an alternate key as it stores unique values for each row.
(d) No, RollNo being the primary key must be unique for each row.

Q8 For the above given database STUDENT-PROJECT, can we perform the following operations?
(d) Insert a student record with missing roll number value.
(e) Insert a student record with missing registration number value.
(f) Insert a project detail without submission-date.
(g) Insert a record with Registration_ID IP-101-19 and ProjectNo 206 in table PROJECT_ASSIGNED.
Ans.
(e) No
(f) Yes
(g) Yes
(h) No, because ProjectNo 206 does not exist in PROJECT table.

TOPIC – SQL BASICS ( DDL AND DML COMMANDS)

PART A , Section I
1. Which command is used to add new record in table?
Ans. INSERT INTO

2.Which option of ORDER BY clause is used to arrange the output in descending order?
Ans. DESC

3 Which command is used to change the existing information of table?
Ans. UPDATE

4 Rajisadatabaseprogrammer,HehastowritethequeryfromEMPLOYEEtabletosearchfor the employee whose name begins from letter „R‟, for this he has written the query as: SELECT * FROM EMPLOYEE WHERENAME=‟R%‟;
Butthequeryisnotproducingthecorrectoutput,helpRajandcorrectthequerysothathe
gets the desired output.
Ans. SELECT * FROM EMPLOYEE WHERE NAME LIKE ‟R%‟;

5. Rajisadatabaseprogrammer,HehastowritethequeryfromEMPLOYEEtabletosearchfor the employee who are not getting any commission, for this he has written the query as: SELECT * FROM EMPLOYEE WHEREcommission=null;
Butthequeryisnotproducingthecorrectoutput,helpRajandcorrectthequerysothathe
gets the desired output.
Ans. SELECT * FROM EMPLOYEE WHERE commission IS null;

6.Rajisadatabaseprogrammer,hastowritethequeryfromEMPLOYEEtabletosearchforthe employeewhoareworkingin„Sales‟or„IT‟department,forthishehaswrittenthequeryas: SELECT*FROMEMPLOYEEWHEREdepartment=‟Sales‟or„IT‟;
Butthequeryisnotproducingthecorrectoutput,helpRajandcorrectthequerysothathe
gets the desired output.
Ans.
SELECT*FROMEMPLOYEEWHEREdepartment=‟Sales‟ordepartment=„IT‟; OR
SELECT * FROM EMPLOYEE WHERE department IN (‘Sales’,’IT’)

7. IfTableSalescontains5recordsandRajexecutedthefollowingqueries;findouttheoutput of both thequery.
(i) Select 100+200 fromdual;
(ii) Select 100+200 fromSales;
Ans.
(i) 300
(ii) 300
300
300
300
300

8.Query to delete all record of table without deleting the table:
a. DELETE TABLETABLE_NAME
b. DELETE FROMTABLE_NAME
c. DROP TABLETABLE_NAME
d. DELETE TABLE FROMTABLE_NAME
Ans. b. DELETE FROM TABLE_NAME

9. Identify the wrong statement about UPDATE command
a. IfWHEREclauseismissingalltherecordintablewillbeupdated
b. OnlyonerecordcanbeupdatedatatimeusingWHEREclause
c. MultiplerecordscanbeupdatedatatimeusingWHEREclause
d. None of theabove
Ans.
b. Only one record can be updated at a time using WHERE clause

10. Identify the correct statement(s) to drop a column from table
a. DELETE COLUMNCOLUMN_NAME
b. DROP COLUMNCOLUMN_NAME
c. ALTERTABLETABLE_NAMEDROPCOLUMNCOLUMN_NAME
d. ALTER TABLE TABLE_NAME DROPCOLUMN_NAME
Ans.
c. ALTERTABLETABLE_NAMEDROPCOLUMNCOLUMN_NAME
d. ALTER TABLE TABLE_NAME DROPCOLUMN_NAME

11. Sunil decides to delete a PhoneNo column from a MySQL Table (student) after insert the data into the table. Write the command to delete that particular column in student table
Ans.
ALTER TABLE student drop PhoneNo

PART A , Section II
1. Consider the following tables EMP and SALGRADE

Database Query using Sql Class 12 Informatics Practices Notes and Questions

a. To display details of all employee in descending order of their DOJ
Ans SELECT * FROM EMPLOYEE ORDER BY DOJ DESC

b .TodisplayNAME,DESIG,SGRADEofthoseemployeewhojoinedintheyear2009
Ans.SELECT NAME,DESIG,SGRADE FROM EMPLOYEE WHERE DOJ LIKE ‘2009%

c. To display all SGRADE, ANNUAL_SALARY from table SALGRADE [where ANNUAL_SALARY = SALARY12]
Ans. SELECT SGRADE,SALARY12 ANNUAL_SALARY FROM SALGRADE

d. To display number of employee working in each SALGRADE from table EMPLOYEE
Ans. SELECT SGRADE,COUNT(*) FROM EMPLOYEE GROUP BY SGRADE

e.To display NAME, DESIG, SALARY, HRA from tables EMPLOYEE and SALGRADE
Ans. SELECT NAME,DESIG,SALARY,HRA FROM EMPLOYEE E,SALGRADE S WHERE

E.SGRADE=S.SGRADE AND SALARY<=50000
2.Give output for following SQL queries as per given table(s):

Database Query using Sql Class 12 Informatics Practices Notes and Questions
Database Query using Sql Class 12 Informatics Practices Notes and Questions

i. SELECT MIN (AVERAGE) FROM GRADUATE
WHERE SUBJECT = “PHYSICS”;
ii. SELECT SUM(STIPEND) FROM GRADUATE WHERE DIV = 2;
iii. SELECT AVG(STIPEND) FROM GRADUATE WHERE AVERAGE >= 65;
iv. SELECT COUNT (distinct SUBJECT) FROM GRADUATE;
v. Write code to rename a table in SQL
Ans.
i. 55
ii. 1000
iii. 450
iv. 4
v. ALTER TABLE RENAME TO ;

PART B, Section I)
1
(i) Sanjay was deleting the record of empno=1234, but at the time of execution of command he forgot to add condition empno=1234, what will be the effect of delete command in this case?
(ii) Sameer is executing the query to fetch the records of employee who are getting salary between 4000 to 8000, he executed the query as –
Select * from employee where salary between 4000 to 8000;
But he is not getting the correct output, Rewrite the correct query.
Ans.
(i) If where clause is missing with DELETE then it will delete all the record of table.
(ii) Select * from employee where salary between 40000 and 80000

Database Query using Sql Class 12 Informatics Practices Notes and Questions

Ans. create table member(id char(6),name varchar(30),fee int(10),doj date)

3. What is data redundancy? What are the problems associated with it?
Ans.
Data redundancy means duplication of data. It causes duplicate data at different locations which destroys the integrity of the database and wastage of storage space.

4. What are referential Integrity Constraints? Describe them?

Ans.

Database Query using Sql Class 12 Informatics Practices Notes and Questions

5. Mr. Sanghi created two tables with City as Primary Key in Table1 and Foreign key in Table2 while inserting row in Table2 Mr Sanghi is not able to enter value in the column City. What is the possible reason for it?
Ans. Mr Sanghi was trying to enter the name of City in Table2 which is not present in
Table1 i.e. Referential Integrity ensures that value must exist in referred table.
PART B, Section II
1.Considering the Visitor table data, write the query

Database Query using Sql Class 12 Informatics Practices Notes and Questions

(i) Write a query to display VisitorName, Coming From details of Female Visitors with Amount Paid more than 3000
(ii) Write a query to display all coming from location uniquely
(iii) Write a query to insert the following values- 7, „Shilpa‟,‟F‟,‟Lucknow‟,3000
Ans.
(i) Select VisitorName,ComingFrom from Visitor
AmountPaid>3000
(ii) Select distinct ComingFrom from Visitor
(iii) insert into visitor values(7,’Shilpa’,’F’,’Lucknow’,3000)

2. Create the following table

Database Query using Sql Class 12 Informatics Practices Notes and Questions

Ans. Create table emp(empno integer Primary Key, Ename varchar(20) NOT NULL, job Char(10), mgr integer, hiredate date, saldecimal(9,2) check(sal>0),comm integer, deptno integer references dept(deptno) on delete cascade);

PART B, Section III

1. Consider the following tables GAMES. Write SQL commands for the statements (i) to (iv) and give outputs for SQL queries (v) to (vi)

Database Query using Sql Class 12 Informatics Practices Notes and Questions

(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;
Ans.
(i) SELECT GameName,Gcode FROM GAMES;
(ii) SELECT * FROM GAMES WHERE PrizeMoney>7000;
(iii) SELECT * FROM GAMES ORDER BY ScheduleDate;
(iv) SELECT SUM(PrizeMoney),Number FROM GAMES GROUP BY Number;
(v) 2
(vi) 19-Mar-2004 12-Dec-2003

2. Consider the following tables STORE and SUPPLIERS and answer (a) and (b) parts of this question:

Database Query using Sql Class 12 Informatics Practices Notes and Questions
Database Query using Sql Class 12 Informatics Practices Notes and Questions

a. Write SQL commands for the following statements:
i. To display details of all the items in the STORE table in ascending order of LastBuy.
ii. To display ItemNo and Item name of those items from STORE table whose Rate is more than 15 Rupees.
iii. To display the details of those items whose supplier code (Scode) is 22 or Quantity in Store (Qty) is more than 110 from the table Store.
iv. To display minimum Rate of items for each supplier individually as per Scode from the table STORE.

b. Give the output of the following SQL queries:
i. SELECT COUNT(DISTINCT Scode) FROM STORE;
ii. SELECT Rate* Qty FROM STORE WHERE ItemNo = 2004;
iii. SELECT Item, Sname FROM STORE S, Suppliers P WHERE S.Scode= P.Scode AND ItemNo = 2006;
iv. SELECT MAX(LastBuy) FROM STORE;
Ans. a.
i. select * from store order by lastbuy;
ii.selectitemno,item from store where rate>15;
iii. select * from store where scode=22 or qty>110;
iv. select min(rate),scode from store group by scode;

b

Database Query using Sql Class 12 Informatics Practices Notes and Questions

TOPIC – SQL QUERIES /FUNCTIONS

1. Character can be stored as ____________.
a. Fixed length strings
b. Variable length strings
c. Either Fixed or Variable length strings
d. None of the above
Sol

Answer

c. Either Fixed or Variable length strings
Char ( ) is fixed length and varchar ( ) is variable length.

2. Query to delete all record of table without deleting the table:
a. DELETE TABLE <TABLE_NAME>;
b. DELETE FROM <TABLE_NAME>;
c. DROP TABLE <TABLE_NAME>;
d. DELETE FROM TABLE <TABLE_NAME>;

Answer

b. DELETE FROM <TABLE_NAME>;

3.Consider a situation where Ravi is assigned a task to see list of departments (Employee Table contain columns (EmpID, Name, Department, Salary, Age), when he executed the query as:
SELECT Department FROM Employee;
He noticed that the same department name is repeated multiple times in query output. What could be possible solution to get Department name uniquely? Rewrite the above query to fetch unique values.

Answer

SELECT DISNTICT Department FROM Employee;

4.The _________ function removes the leading extra spaces from the text.
a. Right( )
b. Trim ( )
c. Left ( )
d. Mid ( )
Sol

Answer

c. left( )

5.What will be the output of the following:
SELECT ROUND(1449.58,-2);
a. 1449.58
b. 1449.00
c. 1400
d. 1449.60

Answer

c. 1400

6 If table Sports contains 6 rows and you executes following query, then what will be the output?
SELECT 15+35 FROM Sports;

Database Query using Sql Class 12 Informatics Practices Notes and Questions

7. What is the minimum number of columns required to create table in mysql?
a. 0
b. 1
c. 2
d. None of the above

Answer

b. 1

  1. 8. What are two main characters used in pattern matching in MySQL?
    a. % and –
    b. % and _
    c. % and *
    d. * and _
Answer

b. % and _ (underscore) are two main characters used in pattern matching

  1. 9. Which aggregate function includes NULL values in their final result?
  2. a. AVG ( )
  3. b. MIN ( )
  4. c. COUNT( )
  5. d. COUNT ()
Answer

d. COUNT (*)

10. Write SQL commands for the following on the basis of given table WORKER

Database Query using Sql Class 12 Informatics Practices Notes and Questions

a. To display details of workers not working in HR and Account department.
b. To find names of workers that begins with V.
c. To retrieve the First Name and Last Name of Worker in single column as Full Name.
d. To find maximum salary of workers having joining between ‘2020-01-01’ and ‘2020-05-30’
e. To display Worker ID and number of years lapsed between Joining Date and Today.

Answer

a. SELECT * FROM worker WHERE Department NOT IN (‘HR’ , ‘Account’);
b. SELECT * FROM worker WHERE First_Name LIKE ‘V%’;
c. SELECT CONCAT(First_Name, “ “ , Last_Name) AS ‘Full Name’ FROM worker;
d. SELECT MAX(salary) AS “Maximum Salary” FROM worker WHERE Joining_Date BETWEEN ‘2020-01-01’ AND ‘2020-05-30’ ;
e. SELECT Worker_ID, YEAR(CURDATE() ) – YEAR (Joining_Date) FROM Worker;

11. For the given table CLUB

Database Query using Sql Class 12 Informatics Practices Notes and Questions
Database Query using Sql Class 12 Informatics Practices Notes and Questions

a To display bonus (10% of Pay) for all Female coaches
b To display details of club where sports contains word ‘ball’
c Display list of coaches with Pay more than 10000 and sorted by age.
d What will be output of below query?
SELECT AVG(Pay) FROM Club WHERE Age=36;
e. What will be output of below query?
SELEC T MIN(Age) FROM Club WHERE Pay>8000;

Answer

a.SELECT Pay*0.10 AS “BONUS” FROM Club WHERE SEX=’F’;
b. SELECT * FROM Club WHERE Sports LIKE ‘%ball%’;
c. SELECT Coachname, Pay FROM Club WHERE Pay >10000 order by Age;

Database Query using Sql Class 12 Informatics Practices

We hope the above Database Query using Sql Class 12 Informatics Practices are useful for you. If you have any questions then post them in the comments section below. Our teachers will provide you an answer. Also refer to MCQ Questions for Class 12 Informatics Practices