Computer Science Term - II Practice Questions
Computer Science Term - II Practice Questions
Data Structure: Stack, operations on stack (push & pop), implementation of stack
using list.
● 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
Relational data model: relation, attribute, tuple, domain, degree, cardinality, keys
(candidate key, primary key, alternate key, foreign key)
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.
The insertion and deletion happens at one end i.e. from the top of the 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.
For example:
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.
For Example:
N=[12, 13, 34, 56, 21, 79, 98, 22, 35, 38]
38 22 98 56 34 12
Ans:-
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
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.
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:
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:-
Ans:- Switch
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
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.
(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.
(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
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.
(iii) Suggest a device/software and its placement that would provide data security for the
entire network of the School.
(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.
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
198
Computer Science
199
Computer Science
200
Computer Science
201
Computer Science
202
MySQL - REVISION TOUR
LAB EXERCISES
Table: Loan_Accounts
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.
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.
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..
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)
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%.
267
MySQL - REVISION TOUR
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.
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.
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.
33. Delete the records of all the loans whose start date is before 2007.
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.
LAB EXERCISES
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.
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.
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:
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
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.
Table: Employee
312