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

Computer Science Term - II Practice Questions

Uploaded by

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

Computer Science Term - II Practice Questions

Uploaded by

Nikhil Tyagi
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 45

CLASS:- XII

SUBJECT:- COMPUTER SCIENCE


TERM-II (2021-22)
PRACTICE QUESTIONS

SYLLABUS (TERM 2):


Unit I: Computational Thinking and Programming – 2

Data Structure: Stack, operations on stack (push & pop), implementation of stack
using list.

Unit II: Computer Networks

● Evolution of networking: introduction to computer networks, evolution of


networking (ARPANET, NSFNET, INTERNET)

● Data communication terminologies: concept of communication, components of


data communication (sender,receiver, message, communication media, protocols),
measuring capacity of communication media (bandwidth, data transfer rate), IP
address, switching techniques (Circuit switching, Packet switching)

● Transmission media: Wired communication media (Twisted pair cable, Co-axial


cable, Fiber-optic cable), Wireless media (Radio waves, Micro waves, Infrared waves

● Network devices (Modem, Ethernet card, RJ45, Repeater, Hub, Switch, Router,
Gateway, WIFI card)

● Network topologies and Network types: types of networks (PAN, LAN, MAN,
WAN), networking topologies (Bus, Star, Tree)

● Network protocol: HTTP, FTP, PPP, SMTP, TCP/IP, POP3, HTTPS, TELNET, VoIP

● Introduction to web services: WWW, Hyper Text Markup Language (HTML),


Extensible Markup Language (XML), domain names, URL, website, web browser, web
servers, web hosting
Unit III: Database Management

Database concepts: introduction to database concepts and its need

Relational data model: relation, attribute, tuple, domain, degree, cardinality, keys
(candidate key, primary key, alternate key, foreign key)

Structured Query Language: introduction, Data Definition Language and Data


Manipulation Language, data type (char(n), varchar(n), int, float, date), constraints
(not null, unique, primary key), create database, use database, show databases, drop
database, show tables, create table, describe table, alter table (add and remove an
attribute, add and remove primary key), drop table,

insert, delete, select, operators (mathematical, relational and logical), aliasing,


distinct clause, where clause, in, between, order by, meaning of null, is null, is not
null, like, update command, delete command

Aggregate functions (max, min, avg, sum, count), group by, having clause, joins :
Cartesian product on two tables, equi-join and natural join

Interface of python with an SQL database: connecting SQL with Python, performing
insert, update, delete queries using cursor, display data by using fetchone(),
fetchall(), rowcount, creating database connectivity applications
Unit I: Computational Thinking and Programming – 2
Q1. Give any two characteristics of stacks.

Ans:- Characteristics of Stacks:

 It is a LIFO data structure

 The insertion and deletion happens at one end i.e. from the top of the stack

Q2. What is stack? Which are two operations performed on stack?.

Ans:- A stack is a data structure whose elements are accessed according to the Last-In First-
Out (LIFO) principle. This is because in a stack, insertion and deletion of elements can only
take place at one end, called top of the stack. Consider the following examples of stacks:

1. Ten glass plates placed one above another. (The plate that is kept last has to be
taken out first)

2. The tennis balls in a container. (You cannot remove more than one ball at a time)

3. A pile of books

4. A stack of coins

Q3. Julie has created a dictionary containing names and marks as key value pairs of 6
students. Write a program, with separate user defined functions to perform the following
operations:

● Push the keys (name of the student) of the dictionary into a stack, where the
corresponding value (marks) is greater than 75.

● Pop and display the content of the stack.

For example:

If the sample content of the dictionary is as follows:

R={"OM":76, "JAI":45, "BOB":89, "ALI":65, "ANU":90, "TOM":82}


The output from the program should be:

TOM ANU BOB OM

OR

Alam has a list containing 10 integers. You need to help him create a program with
separate user defined functions to perform the following operations based on this
list.

● Traverse the content of the list and push the even numbers into a stack.

● Pop and display the content of the stack.

For Example:

If the sample Content of the list is as follows:

N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]

Sample Output of the code should be:

38 22 98 56 34 12

Ans:-

R={"OM":76, "JAI":45, "BOB":89, "ALI":65, "ANU":90, "TOM":82}


def PUSH(S,N):
S.append(N)
def POP(S):
if S!=[]:
return S.pop()
else:
return None
ST=[]
for k in R:
if R[k]>=75:
PUSH(ST,k)
while True:
if ST!=[]:
print(POP(ST),end=" ")
else:
break

Q4. Write a function in Python PUSH(Arr), where Arr is a list of numbers. From this list push
all numbers divisible by 5 into a stack implemented by using a list. Display the stack if it has
at least one element, otherwise display appropriate error message.

OR
Write a function in Python POP(Arr), where Arr is a stack implemented by a list of numbers.
The function returns the value deleted from the stack.

Ans:-

def PUSH(Arr,value):
s=[]
for x in range(0,len(Arr)):
if Arr[x]%5==0:
s.append(Arr[x])
if len(s)==0:
print("Empty Stack")
else:
print(s)
OR

def popStack(st) :
# If stack is empty
if len(st)==0:
print("Underflow")
else:
L = len(st)
val=st[L-1]
print(val)
st.pop(L-1)
Q5. Write a function in python, MakePush(Package) and MakePop(Package) to add a new
Package and delete a Package from a List of Package Description, considering them to act as
push and pop operations of the Stack data structure.

Ans:-
def MakePush(Package):
a=int(input("enter package title : "))
Package.append(a)
def MakePop(Package):
if (Package==[]):
print( "Stack empty")
else:
print ("Deleted element:",Package.pop())
Unit II: Computer Networks
Computer Science

LET'S REVISE
2
Network: A collection of independent computers that communicate with one another over a shared
network medium.
2
Node: A computer attached to a network.
2
Server: A computer that facilitates sharing of data, software and hardware resources on the network.
2
Network Interface Unit (NIU): A device that helps to establish communication between the server and
workstations.
2
Circuit switching: A technique in which a dedicated and complete physical connection is established
between two nodes for communication.
2
Packet switching: A switching technique in which packets are routed between nodes over data links
shared with other traffic.
2
Personal Area Network (PAN): A computer network organized around an individual person.
2
Local Area Network (LAN): A network in which the devices are connected over a relatively short
distance.
2
Metropolitan Area Network (MAN): A network which spans a physical area ( in the range of 5 and 50
km diameter) that is larger than a LAN but smaller than a WAN.
2
Wide Area Network (WAN): A network which spans a large geographical area, often a country or a
continent.
2
Internet: It is a network of networks spread across the globe, all of which are connected to each other.
2
Interspace: A client/server software program that allows multiple users to communicate online with
real time audio, video and text chat in dynamic 3D environments.
2
Channel: A medium that is used in the transmission of a message from one point to another.
2
Bandwidth: The range of frequencies available for transmission of data.

268
Computer Science

EXERCISE
1. Fill in the blanks:
a. Two or more computers connected to each other for information exchange form a _____________.
b. The range of frequencies available for transmission of data is called____________.
c. _____________ is the network of networks.
d. A technique in which a dedicated and complete physical connection is established between two
nodes for communication is ______________switching.
e. Any computer attached on the network is called a ____________.
2. Multiple Choice Questions:
1) Choose the option, which is not included in networking.
a. Access to remote database
b. Resource sharing
c. Power transferring
d. Communication
2) Data transfer rate is often measured in
a. Mbps
b. Kbps
c. Bps
d. gbps
3) Which one of the following is not in the category of communication channels?
a. narrow band
b. broad band
c. light band
d. voice band
4) The greater the bandwidth of a given medium, the ________ is the data transfer rate
a. higher
b. lower
c. both a and b
d. neither a nor b

269
Computer Science

5) What is the approximate bandwidth of a typical voice signal?


a. 2KHz
b. 2MHz
c. 3KHz
d. 3MHz
3. What is a network? Give any two uses of having a network in your school computer lab.
4. Mention any two disadvantages of a network.
5. Two students in the same class sitting inside the same room have connected their laptops using
Bluetooth for working on a group presentation. What kind of network have they formed?
6. Expand the following:
a. ARPANET.
b. PAN
c. NIU
d. MAN
7. What are the requirements for setting up a network?
8. How is a dedicated server different from a non dedicated server?
9. Two companies in different states wanted to transfer information. Which type of network will be used
to implement the same?
10. Two schools in the same city wanted to transfer e-learning information. Which type of network will be
used to implement the same?
11. Two teachers in the same school sitting in different labs wanted to transfer information. Which type of
network will be used to implement the same?
12. Define a protocol. Name any two protocols used on Internet.
13. Differentiate between :
a. Internet and Interspace
b. Circuit Switching and Packet Switching technique
c. LAN , WAN and MAN
14. Define a node and an NIU?
15. Define a channel. Name the three categories of communication channel.
16. What do you mean by bandwidth and DTR?

270
Computer Science

LET'S REVISE
2
Transmission Medium: One which carries a signal from one computer to another.
2
Wired Transmission Media: Twisted Pair, Coaxial , Fibre Optic , Ethernet cable
2
Wireless Transmission Media: Radio waves , Microwaves, Bluetooth , WiFi, Satellites, Infrared
2
Topology: The pattern of interconnection of nodes in a LAN.
2
Network Topologies: Bus , Star, Tree
2
Modem: A device that enables a computer to transmit data over, telephone or cable lines.
2
RJ-45: An eight wired connector used to connect computers on a LAN.
2
Ethernet card: A kind of network adapter.
2
Switch: A small hardware device that joins multiple computers together within a LAN.
2
Repeater: An electronic device that amplifies the received signal and then retransmits it on the
network
2
Router: A network device that connects two networks with different protocols.
2
Gateway: A network device that connects two dissimilar networks.
2
Wi-Fi card: A small, portable card that allow your computer to connect to the internet through a
wireless network.

287
Computer Science

EXERCISE
1. What do you mean by a transmission medium? Differentiate between guided and unguided
transmission media.
2. Explain the structure of a coaxial cable and a fibre optic cable.
3. What are advantages of fibre optic cable?
4. Differentiate between a radio wave transmission and a microwave transmission.
5. Explain satellite communication. What are the advantages and disadvantages of using satellite
communication?
6. Define the term topology.
7. List any two advantages and any two disadvantages of Star topology.
8. How is Tree Topology different from Bus topology?
9. Identify the type of topology from the following.
a. Each node is connected with the help of single cable.
b. Each node is connected with the help of independent cable with central switching.
10. What do you mean by a modem? Why is it used?
11. Explain the following devices:
a. Switch
b. Repeater
c. Router
d. Gateway
e. Wi-Fi Card
12. Show a network layout of star topology and bus topology to connect 4 computers.
13. Ms. Anjali Singh, in charge of Knowledge centre in ABC school, recently discovered that the
communication between her centre and the primary block of the school is extremely slow and signals
drop quite frequently. The distance between these two blocks is 140 meters.
a. Name the type of network.
b. Name the device which may be used for smooth communication.
14. ABC International School is planning to connect all computers, each spread over distance of 50 meters.
Suggest an economic cable type having high speed data transfer to connect these computers.

288
Computer Science

15. Sahil wants to transfer data across two continents at very high speed. Write the name of the
transmission medium that can be used to do the same. Write the type of network also.
16. Mayank wants to transfer data within a city at very high speed. Write the name of the wired
transmission medium that he should use. Write the type of network also.
17. Mr. Akash wants to send/receive email through internet. Which protocol will be used for this
purpose?
18. Answer the following questions in the context of a computer lab with 100 computers.
a. Which device is used to connect all computers inside the lab?
b. Which device is used to connect all computers to the internet using telephone wire?
19. Name the device that establishes an intelligent connection between a local network and external
network with completely different structures.
20. Name the network device that works like a bridge to establish connection between two networks but it
can also handle networks with different protocols.

289
Computer Science

LETS REVISE
2
Protocol: A special set of rules that two or more machines on a network follow to communicate with
each other.
2
Transmission Control Protocol(TCP): It breaks the data into packets that the network can handle
efficiently.
2
Internet protocol(IP): It gives distinct address (called IP address) to each data packet.
2
File Transfer Protocol(FTP): It is used for transferring files from one system to another on the internet.
2
HyperText Transfer Protocol(HTTP): It is the protocol that is used for transferring hypertextfileson
the World Wide Web.
2
Point-to-Point Protocol(PPP): It is usedfor communication between two computers using a serial
interface.
2
Simple Mail Transfer Protocol (SMTP): It allows transmission of email over the Internet.
2
Post Office Protocol 3(POP3): It receives and holds email for an individual until they pick it up.
2
Telnet: A protocol for creating a connection with a remote machine.
2
IRC: IRC protocol is used for chatting.It is based on client/server model.
2
VOIP: VOIP stands for voice over internet protocol. It enables the transfer of voice using packet
switched network rather than using public switched telephone network.

297
Computer Science

EXERCISE
1. Expand the following abbreviations:
FTP, TCP,SMTP,VoIP
2. What do you mean by the term Protocol Independence?
3. Write short notes on:
a) TCP/IP
b) HTTP
c) SMTP
d) FTP
e) Telnet
4. List three important features of HTTP.
5. Explain VOIP.
6. Explain IRC
7. Neha wants to upload and download files from/to a remote internal server. Write the name of the
relevant communication protocol, which will let her do the same.
8. Meha wants to upload hypertext document on the internet. Write the name of protocol, which will let
her do the same.
9. This protocol is used for communication between two personal computers using a serial interface and
connected by a phone line. Write the name of the protocol.
10. This protocol is used to transfer email over internet. What is the name of the protocol?
11. This protocol is used to implement remote login. What is the name of the protocol?
12. This protocol is used for chatting between two groups or between two individuals. Write the name of
the protocol.
13. This protocol is used to transfer of voice using packet switched network. Write the name of the
protocol.
14. Explain Remote Access Protocol.
15. Why we need VoIP protocol?
16. Differentiate between FTP and HTTP.
17. Differentiate between VoIP and IRC.
18. Write the basic hardware requirements for VoIP.
19. Why TCP/IP based applications are considered to be stateless?
20. FTP is based on Client/Server principle. Explain.

298
Computer Science

LETS REVISE
1G Mobile Systems: The 1G Mobile System was introduced in late 1970s and early 1980s.The 1G mobile
system was based on the analog cellular technology. They only had voice facility available.
2G Mobile Systems: They used digital signals for transmissions of voice. 2G enabled the mobile systems to
provide paging, SMS, voicemail and fax services.
3G Mobile Systems: The 3G technology adds multimedia facilities to 2G phones by allowing video, audio,
and graphics applications.
4G Mobile Systems: 4G will provide better-than-TV quality images and video-links.
Virus: Virus is a malicious program that attaches itself to the host program. It is designed to infect the host
program and gain control over the system without the owner's knowledge.
Worm: Worm is also a malicious program like a virus. But unlike viruses, it does not need to attach itself to
a host program. A worm works by itself as an independent object.
Trojan horse: A Trojan horse is a program that contains hidden malicious functions. Trojan Horses trick
users into installing them by appearing to be legitimate programs.
Spam: The term spam means endless repetition of worthless text. In other words, unwanted messages or
mails are known as Spam.
Cookies: This small text file is a cookie. Generally a cookie contains the name of the website that it has come
from and a unique ID tag.
Firewall: A firewall is hardware or software based network security system. It prevents unauthorized
access (hackers, viruses, worms etc.) to or from a network.
Cyber Crime: Cybercrime is defined as a crime in which a computer and internet is used in an illegitimate
way to harm the user.
Cyber Law: Cyber law is an attempt to integrate the challenges presented by human activity on the internet
with legal system of laws applicable to the physical world.
Intellectual property rights are the rights given to an individual over the invention of their own. They
usually give the creator an exclusive right over the use of his/her creation for a certain period of time
Intellectual property rights (IPR) Issues: Intellectual property rights are the rights given to an individual
over the invention of their own. They usually give the creator an exclusive right over the use of his/her
creation for a certain period of time.There are only three ways to protect intellectual property
2
Patents
2
Copyrights

310
Computer Science

2 Trademark
Hacking: The term was used for people who engaged themselves in harmless technical experiments and
fun learning activities.
Cracking: Cracking can be defined as a method by which a person who gains unauthorized access to a
computer with the intention of causing damage.
HyperText Transfer Protocol (HTTP): HTTP is the protocol that is used for transferring hypertext (i.e. text,
graphic, image, sound, video etc.) between two computers and is particularly used on the World Wide
Web. It is a TCP/IP based communication protocol and provides a standard for Web browsers and servers
to communicate.
WWW (World Wide Web): WWW can be defined as a hypertext information retrieval system on the
Internet. Tim Berners -Lee is the inventor of WWW. WWW is the universe of the information available on
the internet.
Web page: Web page is an electronic document designed using HTML. It displays information in textual or
graphical form. It may also contain downloadable data files, audio files or video files.
A web page can be classified into two types:
2
Static web page
2
Dynamic web page
Website: Related webpages from a single wen domain is termed as a website. A website has multiple
webpages providing information about a particular entity.
Web browser: Web browser is software program to navigate the web pages on the internet. A bowser
interprets the coding language of the web page and displays it in graphic form.
URL (Uniform resource locator): Web address of the web page written on the address bar of the browser is
known as the uniform resource locator (URL).
Web hosting: Web hosting is the process of uploading/saving the web content on a web server to make it
available on WWW.
Web 2.0: Web 2.0 refers to new generation of dynamic and interactive websites. Web 2.0 websites uses a
new programming language called AJAX (Asynchronous JavaScript and XML).

311
Computer Science

EXERCISE
1. Differentiate between SMTP and POP3.
2. Give the full forms of the following terms:
2 CDMA
2 TDMA
2 FDMA
3. Briefly explain the generations in Mobile technologies.
4. Differentiate between Worm and Virus
5. Explain different types of viruses briefly.
6. Explain the following terms:
2
Spam
2
Cookies
2
Firewall
7. Explain the significance of IT Act.
8. Explain the following terms:
2
Patent
2
Copyright
2
Trademark
9. Differentiate between hacking and cracking
10. Mona is confused between the terms Domain name and URL. Explain the difference with the help of
suitable example.
11. Identify the Domain name and URL from the following.
http://www.ABCSchool.in/home.aboutus.hml
12. Mr. Rohan wants to prevent unauthorized access to/from his company's local area network. Write the
name of the system, which he should install to do the same.
13. Define the following with reference to threats to network security.
(i) Worm
(ii) Trojan Horse

312
Computer Science

14. In this mode, each user has its own frequency domain. Write the name of this accessing mode.
15. In this mode, each user is allocated with a unique code sequence. Write the name of this accessing
mode.
16. In this mode, each user is allowed to transmit data only within specified time intervals. Write the name
of this accessing mode.
17. It means endless repetition of worthless text. In other words, it contains unwanted messages or mails.
What is the name of this concept?
18. When the user browses a website, the web server sends a text file to the web browser. What is the name
of this?
19. It is defined as a crime in which a computer and internet is used in an illegitimate way to harm the user.
What is the name of this crime?
20. A person who gains unauthorized access to a computer with the intention of causing damage. What is
the name of this crime?

313
Q1. BeHappy Corporation has set up its new centre at Noida, Uttar Pradesh for its office
and web-based activities. It has 4 blocks of buildings.

Distance between the various blocks is as follows:

A to B 40 m
B to C 120m
C to D 100m
A to D 170m
B to D 150m
A to C 70m
Numbers of computers in each block

Block A – 25
Block B - 50
Block C - 125
Block D - 10
(a) Suggest and draw the cable layout to efficiently connect various blocks of buildings
within the Noida centre for connecting the digital devices.
Ans:-
(b) Suggest the placement of the following device with justification

i. Repeater

ii. Hub/Switch

Ans:- Repeater : between C and D as the distance between them is 100 mts.

Hub/ Switch : in each block as they help to share data packets within the devices of
the network in each block

(c) Which kind of network (PAN/LAN/WAN) will be formed if the Noida office is
connected to its head office in Mumbai?

Ans:- WAN.

(d) Which fast and very effective wireless transmission medium should preferably be used
to connect the head office at Mumbai with the centre at Noida?

Ans:- Satellite

Q2. MyPace University is setting up its academic blocks at Naya Raipur and is planning to
set up a network. The University has 3 academic blocks and one Human Resource Center
as shown in the diagram below:

Center to Center distances between various blocks/center is as follows:

Law Block to business Block 40m

Law block to Technology Block 80m

Law Block to HR center 105m

Business Block to technology Block 30m

Business Block to HR Center 35m

Technology block to HR center 15m


Number of computers in each of the blocks/Center is as follows:

Law Block 15

Technology Block 40

HR center 115

Business Block 25

a) Suggest the most suitable place (i.e., Block/Center) to install the server of this
University with a suitable reason.

Ans:- Most suitable place to install the server is HR center, as this center has maximum
number of computers.

b) Suggest an ideal layout for connecting these blocks/centers for a wired connectivity.

Ans:-

c) Which device will you suggest to be placed/installed in each of these blocks/centers to


efficiently connect all the computers within these blocks/centers.

Ans:- Switch

d) Suggest the placement of a Repeater in the network with justification.

Ans:- Repeater may be placed when the distance between 2 buildings is more than 70
meter.

e) The university is planning to connect its admission office in Delhi, which is more than
1250km from university. Which type of network out of LAN, MAN, or WAN will be
formed?

Ans:- WAN, as the given distance is more than the range of LAN and MAN.
Q3. Software Development Company has set up its new center at Raipur for its office and
web based activities. It has 4 blocks of buildings named Block A, Block B, Block C, Block D.

Number of Computers

Block A 25

Block B 50

Block C 125

Block D 10

Shortest distances between various Blocks in meters:

Block A to Block B 60 m

Block B to Block C 40 m

Block C to Block A 30 m

Block D to Block C 50 m

(i) Suggest the most suitable place (i.e. block) to house the server of this company with a
suitable reason.

Ans:- Block C , It has maximum number of computer.

(ii) Suggest the type of network to connect all the blocks with suitable reason .

Ans:- LAN

(iii)The company is planning to link all the blocks through a secure and high speed wired
medium. Suggest a way to connect all the blocks.

Ans:- Star topology

(iv) Suggest the most suitable wired medium for efficiently connecting each computer
installed in every block out of the following network cables:

● Coaxial Cable

● Ethernet Cable

● Single Pair Telephone Cable.

Ans:- Ethernet Cable


Q4. Multipurpose Public School, Bangluru is Setting up the network between its Different
Wings of school campus. There are 4 wings named as SENIOR(S), JUNIOR(J), ADMIN(A)
andHOSTEL(H).

Distance between various wings are given below:

WingA to WingS 100m

WingA to WingJ 200m

WingA to WingH 400m

WingS to WingJ 300m

WingS to WingH 100m

WingJ to WingH 450m

Number of Computers installed at various wings are as follows:

WingA 20

WingS 150

WingJ 50

WingH 25

(i) Suggest the best wired medium and draw the cable layout to efficiently connect
various wings of Multipurpose PublicSchool, Bangluru.

Ans:- Best wired medium: Optical Fibre OR CAT5 OR CAT6 OR CAT7 OR CAT8 OR Ethernet
Cable

Cable layout:-
(ii) Name the most suitable wing where the Server should be installed. Justify your
answer.

Ans:- Wing Senior(S)- Because it has maximum number of computers.

(iii) Suggest a device/software and its placement that would provide data security for the
entire network of the School.

Ans:- Firewall - Placed with the server at Senior

(iv) Suggest a device and the protocol that shall be needed to provide wireless Internet
access to all smartphone/laptop users in the campus of Multipurpose Public School,
Bangluru.

Ans:- Device Name: WiFi Router OR WiMax OR RF Router OR Wireless Modem OR


RFTransmitter Protocol : WAP OR 802.16 OR TCP/IP OR VOIP OR MACP OR 802.11
Unit III: Database Management
Computer Science

EXERCISE
1. Mr. Rohan has created a table 'student' with rollno., name, class and section. Now he is confused to set
the primary key. So identify the primary key column.

2. Ms. Ravina is using a table 'customer' with custno, name, address and phonenumber. She needs to
display name of the customers, whose name start with letter 'S'. She wrote the following command,
which did not give the result.
Select * from customer where name="S%";
Help Ms. Ravina to run the query by removing the errors and write the correct query.
3. Write SQL query to add a column totalprice with data type numeric and size 10, 2 in a table product.
4. The name column of a table 'student' is given below.
Name
Anu Sharma
Rohan Saini
Deepak Sing
Kannika Goal
Kunal Sharma
Based on the information, find the output of the following queries:
2
Select name from student where name like "%a";
2
Select name from student where name like "%h%";
5. A customer table is created with cno,cname, and address columns. Evaluate the following statement
whether it is correct or not?
Delete cname from customer;
6. Shopkeeper needs to change the first name of one of his customers in table 'customer'. Which command
should he use for the same?
7. Sonal needs to display name of teachers, who have "o" as the third character in their name. She wrote
the following query.
Select name
From teacher
Where name ="$$o?";

196
Computer Science

But the query is not producing the result. Identify the problems.
8. Pooja created a table 'bank' in SQL. Later on, she found that there should have been another column in
the table. Which command is used to add column to the table?
9. Surpreeth wants to add two more records of customer in customer table. Which command is used to
implement this?
10. Deepak wants to remove all rows from the tableBank. But he needs to maintain the structure of the
table. Which command is used to implement the same?
11. While creating table 'customer', Rahul forgot to add column 'price'. Which command is used to add
new column in the table. Write the command to implement the same.
12. Write the syntax of creating table command.
13. Write the syntax of dropping table command.
14. What all are the clause possible in select statement.
15. What is the default value of order by command.
16. Differentiate between delete and drop table command.
17. Differentiate between update and alter table command.
18. Differentiate between order by and group by command.
19. Define the following.
a) Union
b) Cartesian product
c) Equi Join
d) Non equi join.
20. What is the use of wildcard?
21. Create the following table items.
Column name Data type Size Constrain
Itemno Number 3 Primary key
Iname Varchar 15
Price Number 10,2
Quantity Number 3

197
Computer Science

22. Insert the following information:


Table: Item
Itemno Iname Price Quantity
101 Soap 50 100
102 Powder 100 50
103 Face cream 150 25
104 Pen 50 200
105 Soap box 20 100
23. Write queries based upon item table given in q. no 22.
a) Display all items information.
b) Display item name and price value.
c) Display soap information.
d) Display the item information whose name starts with letter 's'.
e) Display a report with item number, item name and total price. (total price = price * quantity).
f) Display item table information in ascending order based upon item name.
g) Display item name and price in descending order based upon price.
h) Display item name, whose price is in between 50 to 100.
i) Add new column totalprice with number (10, 2).
j) Increase price value by 100.
k) Fill up totalprice = price * quantity.
l) Remove powder information.
m) Remove totalprice column.
n) Remove whole item structure.
24. Write outputs based upon item table given in q. no 22.
a) select sum(price) from item;
b) select avg(price) from item;
c) select min(price) from item;
d) select max(price) from item;
e) select count(price) from item;
f) select distinct price from item;
g) select count(distinct price) from item;

198
Computer Science

h) select iname,price*quantity from item;


25. In a database there are two tables - 'Brand' and 'Item' as shown below:
BRAND:
ICODE BNAME
100 SONY
200 HP
300 LG
400 SAMSUNG
ITEM:
ICODE INAME PRICE
100 TELEVISION 25000
200 COMPUTER 30000
300 REFRIGERATOR 23000
400 CELL PHONE 40000
Write MYSQL queries for the following:
a) To display Iname, price and corresponding Brand name (Bname) of those items, whose price is
between 25000 and 30000 both values inclusive).
b) To display ICode, Price and BName of the item, which has IName as "Television".
c) To increase the Prices of all items by Rs. 10%.
26. Create the following table
Students
Column name Data type Size Constraints
Adno Integer 3 Primary key
Name Varchar 20
Average Integer 3
Sex Char 1
Scode Integer 4

199
Computer Science

27. Insert the following information:


Students
Adno Name Average Sex Scode
501 R.Jain 98 M 111
545 Kavita 73 F 333
705 K.Rashika 85 F 111
754 Rahul Goel 60 M 444
892 Sahil Jain 78 M 333
935 Rohan Saini 85 M 222
955 Anjali 64 F 444
983 Sneha Aggarwal 80 F 222

28. Write queries based upon item table given in q. no 27.


(i) Display all students' information.
(ii) Display Rohan Saini's information.
(iii) Display number of students in the table.
(iv) Display number of students in each sex.
(v) Display students' information in ascending order using name.
(vi) Display students' information in descending order using average marks.
(vii) Display students' name starting with letter "K".
(viii) Display students' information, whose name ends with "l".
(ix) Display a report with adno,name,average*5 as total marks from student table.
(x) Display students' information, whose average marks are in between 80 to 90.
(xi) Display students' info., who are getting average marks of more than 80 and scode 333.
(xii) Display students' name and average marks, whose scode is 222 and 333.
(xiii) Display sum of average marks.
(xiv) Display maximum average marks
(xv) Display minimum average marks.

200
Computer Science

(xvi) Display average value of average marks.


(xvii) Display maximum, minimum and sum of average marks in each scode.
(xviii) Display number of students in each scode.
29. Create the following table.
Column name Data type Size Constraints
Scode Integer 3 Primary key
Sname Varchar 20
Place Varchar 10

30. Insert the following information.


Streams
Scode Sname Place
111 Science SBlock
222 Commerce CBlock
333 Humanity HBlock
444 Art ABlock

31. Write queries based upon item table given in q. no 27& 30


(i) To display Adno, Name, Sex and Average from Student's table and Stream name (Sname) and
place from Stream table with respect to Scode.
(ii) Add the following information into the student table.
999 Deepak Sharma 83 M 2222
(iii) Display science stream students' information.
32. Give the output of the following SQL queries.
(i) Select sum(Average)
From students
Where sex='M';

201
Computer Science

(ii) Select distinct (Scode)


From students;
33. Remove 111 scode information.
34. Add new column state with varchar(10).
35. Increment 2 marks for 444 scode info.
36. Remove column state.
37. Remove the whole table stream.

202
MySQL - REVISION TOUR

LAB EXERCISES

Consider a database LOANS with the following table:

Table: Loan_Accounts

AccNo Cust_Name Loan_Amount Instalments Int_Rate Start_Date Interest

1 R.K. Gupta 300000 36 12.00 19-07-2009

2 S.P. Sharma 500000 48 10.00 22-03-2008

3 K.P. Jain 300000 36 NULL 08-03-2007

4 M.P. Yadav 800000 60 10.00 06-12-2008

5 S.P. Sinha 200000 36 12.50 03-01-2010

6 P. Sharma 700000 60 12.50 05-06-2008

7 K.S. Dhall 500000 48 NULL 05-03-2008

Write SQL commands for the tasks 1 to 35 and write the output for the SQL commands 36
to 40:
Create Database and use it
1. Create the database LOANS.
2. Use the database LOANS.
Create Table / Insert Into
3. Create the table Loan_Accounts and insert tuples in it.
Simple Select
4. Display the details of all the loans.
5. Display the AccNo, Cust_Name, and Loan_Amount of all the loans.
Conditional Select using Where Clause
6. Display the details of all the loans with less than 40 instalments.
7. Display the AccNo and Loan_Amount of all the loans started before 01-04-2009.

8. Display the Int_Rate of all the loans started after 01-04-2009.

266
MySQL - REVISION TOUR

Using NULL

9. Display the details of all the loans whose rate of interest is NULL.

10. Display the details of all the loans whose rate of interest is not NULL.

Using DISTINCT Clause

11. Display the amounts of various loans from the table Loan_Accounts. A loan amount
should appear only once.

12. Display the number of instalments of various loans from the table Loan_Accounts. An
instalment should appear only once..

Using Logical Operators (NOT, AND, OR)

13. Display the details of all the loans started after 31-12-2008 for which the number of
instalments are more than 36.

14. Display the Cust_Name and Loan_Amount for all the loans which do not have number
of instalments 36.

15. Display the Cust_Name and Loan_Amount for all the loans for which the loan amount
is less than 500000 or int_rate is more than 12.

16. Display the details of all the loans which started in the year 2009.

17. Display the details of all the loans whose Loan_Amount is in the range 400000 to
500000.

18. Display the details of all the loans whose rate of interest is in the range 11% to 12%.

Using IN Operator

19. Display the Cust_Name and Loan_Amount for all the loans for which the number of
instalments are 24, 36, or 48. (Using IN operator)

Using BETWEEN Operator

20. Display the details of all the loans whose Loan_Amount is in the range 400000 to
500000. (Using BETWEEN operator)

21. Display the details of all the loans whose rate of interest is in the range 11% to 12%.

(Using BETWEEN operator)

267
MySQL - REVISION TOUR

Using LIKE Operator

22. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the
Cust_Name ends with 'Sharma'.

23. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the
Cust_Name ends with 'a'.

24. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the
Cust_Name contains 'a'

25. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the
Cust_Name does not contain 'P'.

26. Display the AccNo, Cust_Name, and Loan_Amount for all the loans for which the
Cust_Name contains 'a' as the second last character.

Using ORDER BY clause

27. Display the details of all the loans in the ascending order of their Loan_Amount.

28. Display the details of all the loans in the descending order of their Start_Date.

29. Display the details of all the loans in the ascending order of their Loan_Amount and
within Loan_Amount in the descending order of their Start_Date.

Using UPDATE, DELETE, ALTER TABLE

30. Put the interest rate 11.50% for all the loans for which interest rate is NULL.

31. Increase the interest rate by 0.5% for all the loans for which the loan amount is more
than 400000.

32. For each loan replace Interest with (Loan_Amount*Int_Rate*Instalments) 12*100.

33. Delete the records of all the loans whose start date is before 2007.

34. Delete the records of all the loans of 'K.P. Jain'

35. Add another column Category of type CHAR(1) in the Loan table.

268
1. Consider the following table named "GYM" with details about Fitness products
being sold in the store.

Table Name : GYM

PrCode stores Codes of Products


PrName stores names of Products
(UnitPrice is in Rs.)

Write SQL statements to do the following:

a) Display the names of all the products in the store.


b) Display the names and unit price of all the products in the store
c) Display the names of all the products with unit price less than Rs.20000.00
d) Display details of all the products with unit price in the range 20000 to 30000
e) Display names of all products by the manufacturer "Fit Express"
f) Display all rows sorted in descending order of unit price.
g) Add a new row for product with the details: "P106","Vibro Exerciser",
23000, manufacturer : "Avon Fitness".
h) Change the Unit Price data of all the rows by applying a 10% discount
reduction on all the products.
i) Display details of all products with manufacturer name starting with "A"

2. Consider the following tables Employee and Department.


Write SQL statements to do the following:

a) Display the last names and first names of all employees.


b) Display the Department names of all employees, without duplicates.
c) Display all the details of employees with last name as "Lakshmi".
d) Display all the details of employees whose last name is ""Rajlani" or
"Sharma".
e) Display the codes and first names of all employees of 'Accounts' department.
f) Display department names of departments with budget above 18000.
g) Display all the details of employees whose First name begins with "S".
h) Display department details(from Department table) in descending order of
Budget amount.
i) Change the Department name "Sales" to "Marketing" everywhere in the table
"Employee" and "Department"
j) Add a new row with appropriate data values in Department table.
k) Create the table Department with columns of appropriate data types.
MORE ON DATABASES AND SQL

LAB EXERCISES

1. In a database create the following tables with suitable constraints :

STUDENTS
+-------+----------------+-------+------+------+------------------------+------------------+
| AdmNo | Name | Class | Sec | RNo | Address | Phone |
+-------+----------------+-------+------+------+------------------------+------------------+
| 1271 | Utkarsh Madaan | 12 | C | 1 | C-32, Punjabi Bagh | 4356154 |
| 1324 | Naresh Sharma | 10 | A | 1 | 31, Mohan Nagar | 435654 |
| 1325 | Md. Yusuf | 10 | A | 2 | 12/21, Chand Nagar | 145654 |
| 1328 | Sumedha | 10 | B | 23 | 59, Moti Nagar | 4135654 |
| 1364 | Subya Akhtar | 11 | B | 13 | 12, Janak Puri | NULL |
| 1434 | Varuna | 12 | B | 21 | 69, Rohini | NULL |
| 1461 | David DSouza | 11 | B | 1 | D-34, Model Town | 243554, 98787665 |
| 2324 | Satinder Singh | 12 | C | 1 | 1/2, Gulmohar Park | 143654 |
| 2328 | Peter Jones | 10 | A | 18 | 21/32B, Vishal Enclave | 24356154 |
| 2371 | Mohini Mehta | 11 | C | 12 | 37, Raja Garden | 435654, 6765787 |
+-------+----------------+-------+------+------+------------------------+------------------+

SPORTS
+-------+-------------+-------------+-------+
| AdmNo | Game | CoachName | Grade |
+-------+-------------+-------------+-------+
| 1324 | Cricket | Narendra |A |
| 1364 | Volleball | M.P. Singh |A |
| 1271 | Volleball | M.P. Singh |B |
| 1434 | Basket Ball | I. Malhotra | B |
| 1461 | Cricket | Narendra |B |
| 2328 | Basket Ball | I. Malhotra | A |
| 2371 | Basket Ball | I. Malhotra | A |
| 1271 | Basket Ball | I. Malhotra | A |
| 1434 | Cricket | Narendra |A |
| 2328 | Cricket | Narendra |B |
| 1364 | Basket Ball | I. Malhotra | B |
+-------+-------------+-------------+-------+

a) Based on these tables write SQL statements for the following queries:

i. Display the lowest and the highest classes from the table STUDENTS.

ii. Display the number of students in each class from the table STUDENTS.

iii. Display the number of students in class 10.

iv. Display details of the students of Cricket team.

308
MORE ON DATABASES AND SQL

v. Display the Admission number, name, class, section, and roll number of the
students whose grade in Sports table is 'A'.

vi. Display the name and phone number of the students of class 12 who are play
some game.

vii. Display the Number of students with each coach.

viii. Display the names and phone numbers of the students whose grade is 'A' and
whose coach is Narendra.

b) Identify the Foreign Keys (if any) of these tables. Justify your choices.

c) Predict the the output of each of the following SQL statements, and then verify the
output by actually entering these statements:

i. SELECT class, sec, count(*) FROM students GROUP BY class, sec;

ii. SELECT Game, COUNT(*) FROM Sports GROUP BY Game;

iii. SELECT game, name, address FROM students, Sports

WHERE students.admno = sports.admno AND grade = 'A';

iv. SELECT Game FROM students, Sports

WHERE students.admno = sports.admno AND Students.AdmNo = 1434;

2. In a database create the following tables with suitable constraints :

ITEMS
+--------+--------------+--------------+------+
| I_Code | Name | Category | Rate |
+--------+--------------+--------------+------+
| 1001 | Masala Dosa | South Indian | 60 |
| 1002 | Vada Sambhar | South Indian | 40 |
| 1003 | Idli Sambhar | South Indian | 40 |
| 2001 | Chow Mein | Chinese | 80 |
| 2002 | Dimsum | Chinese | 60 |
| 2003 | Soup | Chinese | 50 |
| 3001 | Pizza | Italian | 240 |
| 3002 | Pasta | Italian | 125 |
+--------+--------------+--------------+------+

309
MORE ON DATABASES AND SQL

BILLS
+--------+------------+--------+-----+
| BillNo | Date | I_Code | qty |
+--------+------------+--------+-----+
| 1 | 2010-04-01 | 1002 | 2 |
| 1 | 2010-04-01 | 3001 | 1 |
| 2 | 2010-04-01 | 1001 | 3 |
| 2 | 2010-04-01 | 1002 | 1 |
| 2 | 2010-04-01 | 2003 | 2 |
| 3 | 2010-04-02 | 2002 | 1 |
| 4 | 2010-04-02 | 2002 | 4 |
| 4 | 2010-04-02 | 2003 | 2 |
| 5 | 2010-04-03 | 2003 | 2 |
| 5 | 2010-04-03 | 3001 | 1 |
| 5 | 2010-04-03 | 3002 | 3 |
+--------+------------+--------+-----+

a) Based on these tables write SQL statements for the following queries:
i. Display the average rate of a South Indian item.
ii. Display the number of items in each category.
iii. Display the total quantity sold for each item.
iv. Display total quanity of each item sold but don't display this data for the
items whose total quantity sold is less than 3.
v. Display the details of bill records along with Name of each corresponding
item.
vi. Display the details of the bill records for which the item is 'Dosa'.
vii. Display the bill records for each Italian item sold.
viii. Display the total value of items sold for each bill.

b) Identify the Foreign Keys (if any) of these tables. Justify your answer.
c) Answer with justification (Think independently. More than one answers may be
correct. It all depends on your logical thinking):
i. Is it easy to remember the Category of item with a given item code? Do you
find any kind of pattern in the items code? What could be the item code of
another South Indian item?

310
MORE ON DATABASES AND SQL

ii. What can be the possible uses of Bills table? Can it be used for some
analysis purpose?
iii. Do you find any columns in these tables which can be NULL? Is there any
column which must not be NULL?
3. In a database create the following tables with suitable constraints :
VEHICLE
+---------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+-------------+------+-----+---------+-------+
| RegNo | char(10) | NO | PRI | | |
| RegDate | date | YES | | NULL | |
| Owner | varchar(30) | YES | | NULL | |
| Address | varchar(50) | YES | | NULL | |
+---------+-------------+------+-----+---------+-------+

CHALLAN
+------------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+------------+----------+------+-----+---------+-------+
| Challan_No | int(11) | NO | PRI | 0 | |
| Ch_Date | date | YES | | NULL | |
| RegNo | char(10) | YES | | NULL | |
| Offence | int(3) | YES | | NULL | |
+------------+----------+------+-----+---------+-------+

OFFENCE
+--------------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------------+-------------+------+-----+---------+-------+
| Offence_Code | int(3) | NO | PRI | 0 | |
| Off_desc | varchar(30) | YES | | NULL | |
| Challan_Amt | int(4) | YES | | NULL | |
+--------------+-------------+------+-----+---------+-------+

a) Based on these tables write SQL statements for the following queries:

i. Display the dates of first registration and last registration from the table
Vehicle.

311
MORE ON DATABASES AND SQL

ii. Display the number of challans issued on each date.

iii. Display the total number of challans issued for each offence.

iv. Display the total number of vehicles for which the 3rd and 4th characters
of RegNo are '6C'.

v. Display the total value of challans issued for which the Off_Desc is 'Driving
without License'.

vi. Display details of the challans issued on '2010-04-03' along with Off_Desc
for each challan.

vii. Display the RegNo of all vehicles which have been challaned more than
once.

viii. Display details of each challan alongwith vehicle details, Off_desc, and
Challan_Amt.

b) Identify the Foreign Keys (if any) of these tables. Justify your choices.

c) Should any of these tables have some more column(s)? Think, discuss in peer
groups, and discuss with your teacher.

4. In a database create the following tables with suitable constraints:

Table: Employee

No Name Salary Zone Age Grade Dept


1 Mukul 30000 West 28 A 10
2 Kritika 35000 Centre 30 A 10
3 Naveen 32000 West 40 20
4 Uday 38000 North 38 C 30
5 Nupur 32000 East 26 20
6 Moksh 37000 South 28 B 10
7 Shelly 36000 North 26 A 30

312

You might also like