Final Notesof Class 12 CS
Final Notesof Class 12 CS
Final Notesof Class 12 CS
1
v. LAN cable : It is used to connect more than one computer or other devices such as
printers and scanners to each other.
Q6. What is TCP/IP?
A6. The Internet works by using a protocol called TCP/IP or Transmission Control
Protocol/Internet Protocol. It allows one computer to talk to another computer via the
internet through compiling packets of data and sending them to right location.
TCP layer handles the message part. The message is broken down into smaller units
called packets which are then transmitted over network.
IP layer is primarily concerned with the transmission portion.
Q7. What is IP addressing?
A7. Every machine on the internet has a unique number assigned to it called an IP
address. An Internet Protocol(IP address) is a numerical label assigned to each
device(e.g. computer, printer) participating in a computer network that uses the
Internet Protocol for communication.An IP address consists of 32 bit of information.
These bits are divided into four sections referred to as octets or bytes, each
containing 1 byte(8 bits). An address space is the total number of addresses used by
the protocol. If a protocol uses N bits to define an address, the address space is 2N
because each bit can have two different values(0 or 1) and N bits can have 2N values.
Q8. Name various classes of IP address?
A8. IPV4 address is divided into two parts :
i. Network ID :This identifies the network to which IP address belongs
ii. Host ID : This identifies host on the specified network.
The IPV4 addressing system is divided into five classes of IP addresses. These are :
Class A, Class B , Class C, Class D , Class E address.
Q9. What is IP routing?
A9. IP routing is a means of specifying and discovering paths in a TCP/IP network along
which network data may be sent. Routing uses a set of routing tables to direct the
forwarding of network data packets from their source to the destination often via
intermediary network nodes known as routers. Two types are :
i. Static routing : It is the manual configuration and selection of a network route,
usually managed by the network administrator.
ii. Dynamic routing : It makes the automatic adjustment of the routes according to
the current state of the route in the routing table.
Q10. What do you mean by network operating system? Explain.
A10. An operating system that provides the connectivity among a number of autonomous
computers is called a network operating system. Network Operating System(NOS)
runs on a server and provides server the capability to manage data, users, groups,
security, applications and other network functions. Its main purpose is to allow
shared file and printer access among multiple computers in a network typically a
local area network, a private network or to other network. E.g. UNIX, LINUX,
Novell Netware
Q11. Give the functions of NOS?
A11. The functions of NOS are :
i. Provides access to remote devices i.e. printers etc.
ii. Enabling and managing access to files on a remote systems and granting
access to users.
iii. Granting access to remote applications and resources such as internet.
iv. Monitoring the system and security so as to provide security against viruses,
hackers etc.
2
Q12. What is Linux Operating System?
A12. The Linux Operating system is a freely distributable operating system based on Unix
that can be installed on PCs, laptops, netbooks, mobile, video game consoles, servers
computers and more.
Q13. Give the three major components of linux structure?
A13. The three major components of linux structure are :
(i). Kernel (ii) Shell (iii) Application
Q14. Write a note on Kernel?
A14. It is the program that is responsible for allocating the computer‟s resources and
scheduling the user jobs in a fair manner. It is also called the heart of the Linux.
Various functions performed by kernels are :
i. Memory management.
ii. Process management
iii. Device management
iv. System call
v. Security
Q15. Write a note on Shell?
A15. Shell refers to the program that is used to interpret the typed commands the user
sends to the operating system. Linux has following types of shells :
i. Bourne Shell : named after its developer “Steve Bourne”. It was the first
shell used for the Unix operating system. It provides
features which are sufficient for most programming
needs.
ii. C Shell : It was designed to allow user to write shell scripts programs
using a syntax similar to C programming language. It is known
as „csh‟
iii. TC Shell : It is an expansion of C shell. It has all the same feature but add
the ability to use keystrokes from the Emacs word processor to
edit text on the command line. It is also known as „tcdh‟
iv. Korn Shell : It was written by „David Korn‟. It attempts to merge the feature
of the C shell, TC shell and Bourne shell under one package. It
also includes the ability for developers to create new shell
commands.
v. Bash Shell : It is the updated version of the original Bourne shell.
Q16. Write a note on applications?
A16. Linux has a variety of high quality softwares which can be easily downloaded and
installed similarly like Windows, Mac.
Q17. Give advantages of Linux?
A17. Advantages of Linux are :
i. Open Source :- It is open source operating system i.e. its source code is easily
available for every one.
ii. Security : Linux is more secure in comparison to other OS such as
Windows.
iii. Software Updates : In Linux you encounter a large number of software
updates. These software updates are much faster than updates in any other OS.
iv. Free to Use(Low Cost) : It is freely available on the web to download and
use.
v. Stability(Reliability) : It provides high stability.
3
vi. Performance : It provides high performance on various networks and
workstations.
vii. Fast and Easy installation : It can be easily installed from the web and
does not require any pre requirements as it can run on any hardware.
4
(x) Grep : This commands searches the named input FILEs for lines
containing a match to the given PATTERN. It is used to find a
string in a file or stream. The syntax is :-
$ grep [options] „string‟ [filename]
e.g. $ grep „hello‟ file1.txt
(xi) Chmd command : It changes the access mode (permission) of one or more
files. Only the owner of the file or a privileged user may change the mode.
Mode can be numeric or an expression in the form of who opcode permission.
The syntax is :-
$ Chmod [options] mode files
e.g. $ chmod u=rwx , g = rx , o = r myfile
(xii) Cat command : The cat(short for “concatenate”) command allows to
create single or multiple files, view content of file , concatenate files
and redirect output in terminal or files. The cat command is used for :-
a. Display text file on screen : the syntax is
$ cat abc.txt
b. Create a new text file : the syntax is :
$ cat>newfile
c. Append data in a text file : the syntax is :
$ cat>> abc.txt
d. File concatenation : the syntax is :
$ cat file1 file2 >newfile
(xiii) Find : It is used to find the files in the hard drive. The syntax is :
e.g. $ find /user/bin – type f – name “*.txt”
(xiv) Date command : It is used to display the current system date and time. The
syntax is :- $ date
(xv) Cal : It is used to print a 12 month calendar for a given year. The
syntax is :
$ cal 2019
(xvi) Cmp : It compares two files that they are identical. It shows 0 if they
are identical otherwise it shows 1. The syntax is
$ cmp file1 file2
(xvii) Sort : It print the lines of file in sorted order. The syntax is :
$ sort filename
(xviii) Ps :- It is used to view the processes that user is running. The syntax
is : $ ps [option]
e.g. $ ps – u username displays the processes of the
specified.
(xix) Kill : It is used for terminating the process. The syntax is :
$ kill processid
(xx) Netstat : It display the network status. It prints information about active
socket, routing table, interfaces etc. the syntax is :
$ netstat
(xxi) Logout : It is used for logging out the Linux. The syntax is :
$ logout
5
Q20. What are wildcards?
A20. Wildcards are a set of characters that allow you to create a pattern defining a set of
files or directories. The basic type of wild cards are :
i. * represents zero or more character
e.g. if user want to display files beginning with „F‟ :
$ ls F*
ii. ?represents a single character
e.g. $ ls F????.txt
the output will be : First.txt File1.txt File2.txt
Q21. What is I/O redirection?
A21. Redirection is a feature in Linux such that when executing a command you can
change the standard input/output devices. The basic workflow of any linux command
is that it takes an input and gives an output. The standard input device is the
keyboard. The standard output device is the screen.
Q22. What is output redirection?
A22. The output from a command normally intended for standard but it can be easily
diverted to a file. This capability is known as output redirection. A greater than
character(>) is used for output redirection.
e.g. $ who > users
Here no output appears at the terminal because the output has been redirected from
the default output(the terminal) into the specified file.
Q23. What is input redirection?
A23. Input of a command can be redirected from a file. The less-than character(<) is used
to redirect the input of a command.
e.g. $ command [arguments] < filename
$ mail ram <mail_contents
Here the text file mail_contents will be used as input for command mall ram.
Q24. What is pipelines?
A24. Pipes are used to redirect a stream from one program to another. We pipe the output
of one program to the input of another. A pipe is nothing but a temporary storage
place where the output of one command is stored and then passed as the input for
second command. It is represented by a vertical bar ( | ).
The syntax is :
$ command1 | command2
e.g. $ ls | lpr
here the list of filenames output by ls command is piped into the lpr command.
Q25. What do you mean by vi editor? Explain.
A25. Vi stands for visual editor. It is used for editing files in Linux. It operates in three
modes :-
i. Regular mode :- It allows typing commands. In regular mode you can move
the cursor around with the arrow keys. E.g. press the x key to delete the
character.
ii. Insertion mode :- It is used to insert a character inside a document. To
switch to insertion mode press the key Insert on your keyboard or press key i.
iii. Replacement mode :- It allows to replace existing text by the text you
capture. Just hit r again to goto replacement mode and hit the key ESC to
return to regular mode.
6
Q26. What is cyber crime?
A26. The crimes committed with the use of computers or relating to computer using
internet is called cyber crime. The most common type are :
i. Fraud : is used to describe a cybercrime that intends to deceive a person
in order to gain important data or information.
ii. Hacking : It involves the partial or complete acquisition of certain
functions within a system, network or website. It also aims to
access to important data and information, breaching privacy.
iii. Computer viruses : Most criminal take advantage of viruses to gain
unauthorized access to systems and steal important data.
iv. Spamming : It uses electronic messaging systems, most commonly emails in
sending message that host malware, fake links of websites and
other malicious programs.
v. Phishing : Phishers act like a legitimate company or organization. They use
email spoofing to extract confidential information such as credit
card numbers, social security number, passwords etc.
Q27. What is cyber law?
A27. It is a generic term which refers to all the legal and regulatory aspects of internet and
world wide web.
7
Chapter-2
Network Operating System Administration(Configuration and Maintenance)
Q1. What do you mean by network operating system? Explain.
A1. An operating system that provides the connectivity among a number of autonomous
computers is called a network operating system. Network Operating System(NOS)
runs on a server and provides server the capability to manage data, users, groups,
security, applications and other network functions. Its main purpose is to allow
shared file and printer access among multiple computers in a network typically a
local area network, a private network or to other network. E.g. UNIX, LINUX,
Novell Netware
Q2. Give the functions of NOS?
A2. The functions of NOS are :
i. Provides access to remote devices i.e. printers etc.
ii. Enabling and managing access to files on a remote systems and granting
access to users.
iii. Granting access to remote applications and resources such as internet.
iv. Monitoring the system and security so as to provide security against viruses,
hackers etc.
Q3. What do you mean by maintenance? Explain.
A3. Maintenance is a regular and systematic inspection, cleaning and replacement of
worn parts, materials and systems. Preventive maintenance helps to prevent the
failure of parts , material and systems by ensuring that they are in good working
order.
Q4. Give five elements of maintenance and management of network?
A4. There are five major elements to the maintenance and management of a network.
They are :
i. Fault management.
ii. Configuration management.
iii. Performance management.
iv. Security management.
v. Accounting management.
Q5. What is network security?
A5. Network security is the process of taking preventative measures to protect the
underlying networking infrastructure from unauthourised access, misuse,
malfunction, modification, destruction or improper disclosure. It involves the
authorization of access to data in a network, which is controlled by the network
security administrator/specialist.
Q6. Give the responsibilities of network security specialist?
A6. The responsibilities for network security specialist are as follows :
i. Analyze IT specifications to assess security risks.
ii. Design and implement safety measures and data recovery plans.
iii. Install, configure and upgrade security software.
iv. Secure networks through firewalls, password protection and other systems.
v. Inspect hardware for vulnerable points of access.
vi. Monitor network activity to identify issues early and communication them to
IT teams.
vii. Act on privacy breaches and malware threats.
viii. Serve as a security expert and conduct trainings when needed.
ix. Draft policies and guidelines.
8
Q7. What are the various career opportunities for network specialist?
A7. The various career opportunities for network specialist are as follows :
i. Network technician.
ii. System Engineer
iii. System Architect
iv. Network Engineer
v. Field Engineer
vi. Network Security Manager
vii. Network Analyst
Q8. What is Window NT? Give its advantages and disadvantages?
A8. Windows NT is a 32-bit network operating system developed by Microsoft for users
and businesses needing advanced capability. Windows NT have two products :
Microsoft NT Workstation and Microsoft NT Server. The characteristics of Windows
NT are :-
It is multitasking system, it is multi-user system, it supports numerous network
features and security.
The advantages of Windows NT are :-
i. More pleasing to the eye.
ii. Low system requirements.
iii. Runs well on old machines if all patches are installed.
iv. Faster to operate.
v. Easier to install.
vi. Security .
The disadvantages of Windows NT are :-
i. More easy to catch viruses and malware.
ii. Crashes if patches are not installed.
Q9. What is the difference between linux and windows operating system? Explain.
A9. The difference between linux and windows are as follows :
LINUX WINDOWS
1 Linux is an open source operating Windows does not provide the users
system(OS) access to the programming code that
forms the basis for foundation of this OS
2. No licensing is used to use linux software. The user should have license to use this
software.
3. It is available free of cost. The users has to pay for this software.
4. Users can install an application without Internet connection is needed to install
using internet support. application in windows.
5. Linux is much more secured as compared to Windows continues to be the most
windows. vulnerable to viruses, malware and other
attacks and is less secure.
6. It can be installed on a wide variety of Windows can be installed on PC‟s,
computer hardware, ranging from mobiles desktops, laptops, servers and some phones.
phones, tablet computers and video game
consoles, to mainframes and
supercomputers.
9
Q10. What is Linux Firewall?
A10. Firewall is a network security system that filters and controls the traffic on a
predetermined set of rules. This is an intermediary system between the device and the
internet.
A network firewall protects your computer from attacks or intrusions from malicious
crackers in the network. A properly configured firewall can increase the security of
computer.
Q11. Name five types of firewall?
A11. The five types of firewall are as follows :
i. Packet filtering firewall.
ii. Circuit Level Gateway.
iii. Stateful inspection firewall.
iv. Application Level Gateway.
v. Next Generation Firewall.
Q12. What is Logical Volume Manager(LVM)?
A12. LVM stands for Logical Volume Management. It is a system of managing logical
volumes or file systems that is much more advanced and flexible than the traditional
method of partitioning a disk into one or more segments and formatting that partition
with a file system. There are three concepts that LVM manages :
i. Volume Groups : is used for changing what abstracted set of physical
partitions are presented to your operation in logical volumes.
ii. Physical Volumes : used for adding or removing hard drives in volume
group.
iii. Logical Volumes : It will present the volume groups as partitions so that
operating system can use the designated space.
Q13. What is a SWAP Space? Explain.
A13. It is used when the amount of physical memory(RAM) is full. If the system needs
more memory resources and the RAM is full, inactive pages are moved to the swap
space. While swap space can help machines with a small amount of RAM, it should
not be considered a replacement for more RAM. It is located on hard drives which
have a slower access time than physical memory.
Q14. What is mount point in linux?
A14. Mount is to access a filesystem in Linux. In Red Hat Linux each partition is used to
form part of the storage necessary to support a single set of files and directories. This
is done by associating a partition with a directory through a process known as
mounting. Mounting a partition makes its storage available starting at the specified
directory known as a mount point.
Q15. What do you mean by shell scripting? Explain.
A15. Shell is a program that acts as an interface between the user and the Linux kernel.
The shell is a command line interpreter. Whenever we enter a command it is
interpreted by the Linux shell. A shell script is file that contains ASCII text. Shell
script is series of command written in plain text file.
Q16. Why do we need shell scripts?
A16. There are many reasons to write shell scripts :
i. To avoid repetitive work and automation.
ii. System admins use shell scripting for routine backups.
iii. System monitoring.
iv. Adding new functionality to the shell etc.
10
Q17. Give advantages of shell scripts?
A17. The advantages of shell scripts are :
i. The command and syntax are exactly the same as those directly entered in
command line, so programmer do not need to switch to entirely different
syntax.
ii. Writing shell scripts are much quicker.
iii. Quick start.
iv. Interactive debugging etc.
Q18. Give disadvantages of shell scripts?
A18. Various disadvantages of shell scripting are :
i. Prone to costly errors, a single mistake can change the command which might
be harmful.
ii. Slow execution speed.
iii. Design flaws within the language syntax or implementation.
iv. Not well suited for large and complex task.
Q19. What do you mean by Red Hat Linux? Explain.
A19. It is the enterprise grade version of Red Hat‟s open source Linux operating system
distribution. It can be deployed on both servers and desktops.
Q20. What are responsibilities of network security specialist?
A20. A network security specialist is a kind of computer administrator that specializes in
protecting a company‟s data and other information. Network security specialists build
firewall, install antivirus software on servers and computers within a network and monitor
network for breaches in security. A Network security specialist often provides training to
general staff regarding security issues and he may develop policies that govern how
employees can access company information using a smartphone, laptop or home computer.
Q21. What do you mean by linux firewall? What are three levels of security provided
by linux firewall?
A21. A network firewall protects your computer from attacks or intrusions from malicious
crackers in the network. A firewall exists between your computer and the internet. A
properly configured firewall can increase the security of computer. There are three
different levels of security :
i. Highly secure firewall : it is suitable for those who are quite concerned about
their security. Here all incoming network connections are disallowed unless
specifically listed in the services list on the screen.
ii. Medium grade secure firewall : this is default level of security and is
generally adequate while using the internet.
iii. No firewall : It allows any outside individuals to access network resources on
your computer.
Q22. What is the purpose of root user in Linux? Explain.
A22. To perform system administration operations we must have access rights such as the correct
password that enable to log in as root user, making us the superuser. Because the superuser
i.e. root user have the power to change almost anything on the system. With the correct
password, we can log in to the system as a system administrator and configure the system in
different ways.
Q23. What are the command for adding and deleting a user in Linux?
A23. Adduser allows to add a single user to the system. All the parameters must be specified on
the command line. The syntax is :sudoadduser username
The command to delete a user is deluserl. With the – r option, the user‟s home directory will
also be removed. The syntax is :sudodeluser username
11
Chapter-3
Desktop Publishing(Advanced)
13
Q10. Explain the following : (i) Pixel (ii) PPI
A10. Pixel : It is a single square on a computer screen. Depending upon your screen
resolution your screen probably has hundreds of thousands of pixels. E.g. the most
common screen resolution currently is 1074 x 768 which comes out to 786,432
pixels.
PPI : It stands for Pixels Per Inch, the standard unit of measurement for computer
graphics(sometimes known as dpi or dots per inch)
14
Q14. What do you mean by view modes? Explain.
A14. A feature by which we can view a drawing. Corel Draw provides six modes to view a
drawing. They are as follows :-
i. Simple Wireframe mode displays the outlines of the object in the drawing in
monochrome but hides the fills, contours and blends.
ii. Wireframe mode displays the outlines, contours and blends of the objects in
the drawing in monochrome but hides the fills.
iii. Draft mode displays the drawing in low resolution and displays texture and
pattern fills in grayscale.
iv. Normal mode displays the drawing in high resolution with smooth edges.
v. Enhanced mode displays the drawing in high resolution with smooth edges.
vi. Enhanced with overprints mode displays the drawing in high resolution with
smooth edges and also shows how colors will appear if you are overprinting
objects.
15
Q19. How can you lock and unlock objects? Explain.
A19. The steps to lock objects are as follows :-
i. Select the object or group of objects using Pick Tool.
ii. Click Arrange Lock Object Option
iii. The selected object will be locked.
The steps to unlock the object are as follows :-
i. Select the locked objects using Pick Tool.
ii. Click Arrange UNLock Object Option
iii. The locked object will be unlocked.
Q20. How can you import files from Corel Draw?
A20. The steps to import files in Corel Draw are as follows :-
i. Click File Import
ii. Choose the folder where the file is stored.
iii. Choose a file format from the files of type list box.
iv. Click the filename.
v. Click import and do one of the following :-
Click the drawing page to maintain original file and position top-left corner
where you click.
Click and drag on the drawing page to resize the file.
v. Click options and enable any of the following active check box :
Export this page only.
Selected only.
Do not show filter dialog.
vi. Click Export.
**************************************************************************
16
Chapter-6(Elementary Server Side Scripting Using PHP
17
Q7. What are the advantages of PHP? Explain.
A7. The advantages of PHP are as follows :
i. It is fast.
ii. It is open source software.
iii. It is easy to use.
iv. It can run on many operating systems.
v. Technical supports is widely available.
vi. It is designed to support databases.
vii. It is customizable
Q8. What do you mean by WAMP server? Explain.
A8. WAMP stands for “Windows , Apache, MySQL and PHP”. It is often used for web
development and internal testing but may also be used to serve live websites. WAMP
includes PHP and MySQL, which are two of the most common technologies used for
creating dynamic websites. MySQL is a high-speed database, while PHP is a
scripting language that can be used to access data from the database. By installing
these two components locally, a developer can build and test a dynamic website
before publishing it to a public web server. The most important part of the WAMP is
Apache which is used to run the web server within Windows. By running a local
Apache web server on a Windows machine, a web developer can test web pages in a
web browser without publishing them live on internet.
Q9. What is the syntax of PHP script? Explain.
A9. A PHP script starts with
<?php and ends with ?>.
Its syntax is :
<?php
// PHP Code
?>
The default file extension for PHP file is “.php”. A PHP file normally contains
HTML tags and some PHP scripting code.
Q10. What is the purpose of print and echo command? Explain.
A10. The print() statement is used to display the data. The syntax is as follows :
Intprint(argument)
Echo() statement have the same purpose as print() statement. It is used to print the
data. The syntax is :
Echo(string argument1 [, …string argument])
Q11. What is the purpose of comments in PHP? Explain.
A11. A comment is a non executable statement that helps to read and understand a
program. Comments may appear anywhere in the program. PHP has two types of
comments :
i. Single-line comments : It starts with double slash symbol(//) and terminates
at the end of current line. E.g.
// My first web page.
ii. Multiline comment : It begins with /* and ends with */
e.g
/* My first
Web Page. */
18
Q12. What do you mean by variables?
A12. A variable is a name associated with value. A variable stores or contains the value.
Variables allow you to store and manipulate data in program. It can hold any value
during the execution of the program. It‟s value can be changed during program
execution.
Q13. What are the rules for declaring variable names?
A13. The rule for declaring variables names are as follows :
i. A variable starts with $ sign, followed by the name of the variable.
ii. A variable name must start with a letter or the underscore character.
iii. A variable name cannot start with a number.
iv. Variable names can be any length.
v. Variable names can include letters, numbers and underscores only.
vi. Variable names are case-sensitive e.g. $name and $NAME are two different
variable.
Q14. What do you mean by scope of variables? Explain.
A14. The scope of a variable is the region of program in which it is defined. PHP has three
different variable scopes :
i. Local : A variable which is declared inside function is called local variable. It is
accessible within the function only.
ii. Global : It is a variable relevant throughout the entire program. A variable
declared outside the function or declared with window object is known as global
variable.
iii. Static : When a function is completed/executed, all of its variable are deleted.
However sometimes we want a local variable NOT to be deleted. We need it for a
further job. To do this use the static keyword when you first declare the variable.
Q15. What do you mean by data types?
A15. Values stored in a variable or a constant are stored as a specific type of data. PHP
provides different data types to hold different types of values.
Q16. What are various data types in PHP? Explain.
A16. The various data types in PHP are as follows :
i. Integers : Whole numbers, without a decimal point e.g. 24 , 73 , -33 etc.
ii. Floating point number : A numeric value with decimal digits e.g 7.35
iii. String : A series of characters e.g. “All is well”
iv. Boolean : A value that can be either true or false.
v. Array : A group of values in one variable.
vi. Object : A structure created with a class.
vii. Resource : A reference that identifies a connection.
viii. NULL : A special type that only has one value NULL
Q17. What is the purpose of if statement? Explain.
A17. The if statement is used to execute one or more lines of code based on a condition.
This statement executes one block of statements if the condition is True. The syntax
is :
If(condition)
{
Code to be executed
}
19
Q18. What is the purpose of switch statement? Explain.
A18. It is a multi way branching statement. This statement causes a particular group of
statements to be chosen from several available groups. The selection is based on the
current value of expression that is included within switch statement. The interpreter
checks each case against the value of the expression until a match is found. If nothing
matches a default will be used. The syntax is :
Switch(n)
{
Case label1:
Code to be executed;
Break;
Case label2:
Code to be executed;
Break:
………..
………..
Default:
Code to be executed;
}
Q19. What is the purpose of FOR statement? Explain.
A19. The for loop is a block of statements that is used to carry out a looping operation i.e.
to execute a sequence of statements fixed number of times. A PHP for loop exectes a
block of statements until a specified condition is true. The syntax is :
For(init counter; test counter; increment/decrement counter)
{
Code to be executed;
}
Where :
Initcounter : initialize the loop counter value.
Test counter : evaluated for each loop iteration. If it evaluates to TRUE, the
loop continues. If it evaluates to FALSE, the loop ends.
Increment/decrement counter : Increases/decreases the loop counter value.
Q20. What do you mean by functions? Explain.
A20. A function is a block of code. Functions can be built-in or user defined. They can require
information to be passed to them and usually return a value. A function is a self contained
block of statements that perform a specific task. A function accepts values from user,
processes them and then perform an action or returns a new value, possibly both. Using
function it is possible to reduce the size of program by calling and using them at different
places in a program.
Q21. Give advantages of using functions?
A21. Various advantages of using functions are as follows :
i. Easy to write a correct and small function.
ii. Easy to read, write and debug a function.
iii. Easier to maintain or modify such a function
iv. Small functions tend to be self documenting and highly readable.
v. It can be called any number of times in any place with different parameters.
vi. Reducing duplication of code.
vii. Decomposing complex problems into simpler pieces.
viii. Improving clarity of the code.
ix. Reuse of code.
x. Information hiding.
20
Q22. What do you mean by array? Explain.
A22. An array is a collection of identical data objects which are stored in consecutive
memory locations under a common heading or variable name. Arrays are complex
variables that stores multiple or a group of values under a single variable name. It is a
special variable which can hold more than one value at a time. There are three types
of arrays in PHP :
i. Indexed array : An array with a numeric key.
ii. Associative array : An array where each key has its own specific value.
iii. Multidimensional array : An array containing one or more arrays within
itself.
Q23. What do you mean by Get and Post methods? Explain.
A23. GET method : The form data is passed by adding it to the URL that calls the
form processing program. The GET method sends the encoded user information
appended to the page request. The GET method is restricted to send upto 1024
characters only. The advantages of this method are simplicity and speed.
The disadvantages are that less data can be passed and that the information is
displayed in the browser, which can be a security problem in some situations.
POST method : The form data is passed as a package in a separate
communication with the processing program. The POST method transfers
information via HTTP headers. The information is encoded as described in case of
GET method and put into a header called QUERY_STRING.
The advantages of this method are unlimited information passing and security of the
data.
The disadvantages of this method are the additional overhead and slower speed.
Q24. What do you mean by session variables? Explain.
A24. A session is the time that a user spends at web site. When work with an application
you open it, do some changes and then you close it. This is much like session. Users
can view many web pages between the time they enter the site and leave it. PHP
enables you to set up a session on one web page and save variables as session
variables.
21
Q26. What do you mean by operators? Give various operators used in PHP.
A26. Operators are used to perform operations on variables and values. PHP divides the
operators in the following groups :
i. Arithmetic operators : These operators are used with numeric values to perform
common arithmetical operations such as addition, subtraction, multiplication,
division etc.
ii. Assignment operator : These are used with numeric values to write a value to a
variable. e.g $ x=10 , $x + = $ y , $ x % = $y etc.
iii. Comparison operators : These are used to compare two values (number or string)
e.g. $x > 10 , $x <= 30 etc
iv. Increment/Decrement operator : The increment operator is used to
increment a variable value e.g. ++ $x
Decrement operator is used to decrement the value of variable e.g - - $x
v. Logical operators : These are used to combine conditional statements.
e.g AND , OR , NOT , XOR
vi. String operator : these are used specially designed for strings e.g concatenation
vii. Array operators : these are used to compare arrays.
22
Practicals Q/A
PHP
23
Q3. Write a program in php to find sum of two variables:
A3. <html>
<head>
<title> PHP Script</title>
</head>
<body>
<?php
$x=15;
$y=41;
echo $x + $y;
?>
</body>
</html>
Q4. Write a program to demonstrate a local scope variable?
A4. <html>
<head>
<title> Local Scope variable
</title>
</head>
<body>
<?php
Function mytest()
{
$x=5; // local scope
Echo “<p>Variable x inside function is : $x</p>”;
}
Mytest();
//using x outside the function will generate an error
Echo “<p> Variable x outside function is : $x</p>”;
?>
</body></html>
Q5. Write a program to demonstrate a global keyword before the variable(inside the function)?
A5.
<html>
<head>
<title> Global Scope variable
</title>
</head>
<body>
<?php
functionmytest()
{
Global $x, $y;
$y=$x + $y;
}
mytest();
Echo $y:// outputs 15
?>
</body></html>
24
Q6. Write a program to demonstrate the static keyword?
A6.
<html>
<head>
<title> Static Scope variable
</title>
</head>
<body>
<?php
functionmytest()
{
Static $x=0;
Echo $x;
$x++;
}
Mytest();
Mytest();
Mytest();
?>
</body>
</html>
Q7. Write a program to demonstrate if statement?
A7. <html>
<head>
<title>If statement
</title>
</head>
<body>
<?php
$t=date(“H”);
if($t<”20”)
{
Echo “Have a good day!”;
}
?>
</body>
</html>
25
Q8. Write a program to demonstrate if else statement?
A8.
<html>
<head>
<title> If else statement
</title>
</head>
<body>
<?php
$t=date(“H”);
If($t<”20”)
{
Echo “Have a good day!”;
}
else
{
Echo “Have a good night!”;
}
?>
</body></html>
Q9. Write a program to demonstrate if elseif statement?
A9. <html>
<head>
<title> If elseif statement
</title>
</head>
<body>
<?php
$t=date(“H”);
If($t<”10”)
{
Echo “Have a good morning!”;
}
Elsif($t<”20”)
{
Echo “Have a good day!”;
}
Else
{
Echo “Have a good night!”;
}
?>
</body></html>
26
Q10. Write a program to demonstrate switch statement?
A10.
<html>
<head>
<title> Switch statement
</title>
</head>
<body>
<?php
$fcolor=”red”;
switch($fcolor)
{
case “red”:
Echo “Your favorite color is red!”;
Break;
case “blue”:
echo “Your favorite color is blue!”;
break;
case “green”:
echo “Your favorite color is green!”;
break;
default :
echo “Your favorite color is neither red, blue nor green!”;
}
?>
</body></html>
27
Q11. Write a program to find the greatest number among three number?
A11.
<html>
<head>
<title> Greatest among three numbers
</title>
</head>
<body>
<?php
$a=20;
$b=10;
$c=30;
If($a>$b)
{
If($a>$c)
{
Echo “Greatest number is = “,$a;
}
Else
{
Echo “greatest number is = “,$c;
}
Else
{
If($b>$c)
{
Echo “greatest number is = “, $b;
}
Else
{
Echo “greatest number is = “, $c;
}
}
?>
</body></html>
Q12. Write a program to find whether given year is a leap year or not leap year?
A12.
<html><head>
<title> Leap Year </title></head><body>
<?php
$y=2000;
If($y%4==0 || $y%100!=0 || $y%400==0)
{
Echo $y. “is a leap year”;
}
Else
Echo $y. “ is not a leap year”;
?>
</body></html>
28
Q13. Write a program to find the day fall on a given date of a month. It is given that
month start with Monday.
A13.
<html>
<head>
<title></title></head>
<body>
<?php
$d=14;
$r=$d%7;
Switch($r)
{
Case 1:
Echo “on date “.$d. “ of this month is Monday”;
Break:
Case 1:
Echo “on date “.$d. “ of this month is Monday”;
Break:
Case 2:
Echo “on date “.$d. “ of this month is Tuesday”;
Break:
Case 3:
Echo “on date “.$d. “ of this month is Wednesday”;
Break:
Case 4:
Echo “on date “.$d. “ of this month is Thrusday”;
Break:
Case 5:
Echo “on date “.$d. “ of this month is Friday”;
Break:
Case 6:
Echo “on date “.$d. “ of this month is Saturday”;
Break:
default:
Echo “on date “.$d. “ of this month is Sunday”;
}
?>
</body></html>
29
Q14. Write a program to demonstrate while loop?
A14.
<html>
<head>
<title></title></head>
<body>
<?php
$x=1;
While($x<=5)
{
Echo “The number is : $x <br>”;
$x++;
}
?>
</body></html>
30
Q17. Write a program to print all the even number from 10 to 50?
A17.
<html>
<head>
<title></title></head>
<body>
<?php
Si = 10;
While($i<=50)
{
If($i%2==0)
{
Echo “<br> Even Number = “.$i;
$i=$i + 1;
}
}
?>
</body></html>
Q18. Write a program to find the factorial of a given positive number?
A18.
<html>
<head>
<title></title></head>
<body>
<?php
$n=5;
$f=1;
For($i=$n;$i>0;$i--)
{
$f=$f * $i;
}
Echo “<br>Factorial of the given number = “,$f;
?></body></html>
Q19. Write a program to find the m raise to power n?
A19.
<html>
<head>
<title></title></head>
<body>
<?php
$m=4;
$n=3;
$t=1;
For($i=1;$i<=$n;$i++)
{
$t=$t * $m;
}
Echo $m. “Raise to power “.$n. “ = “.$t;
?></body></html>
31
Q20. Write a program to demonstrate foreach loop?
A20.
<html>
<head>
<title></title></head>
<body>
<?php
$colors=array(“red”,”green”,”blue”,”yellow”);
Foreach($colors as $value)
{
Echo “$value <br>”;
}
?>
</body></html>
Q21. Write a program to demonstrate a user defined function?
A21.
<html>
<head>
<title></title></head>
<body>
<?php
Function writemsg()
{
Echo “Hello everybody!”;
}
Writemsg(); // call the function
?>
</body></html>
Q22. Write a program to demonstrate an indexed array?
A23.
<html>
<head>
<title></title></head>
<body>
<?php
<?php
$cars=array(“Maruti”,”BMW”,”Toyota”);
$arrlength=count($cars);
For($x=0;$x<$arrlength;$x++)
{
Echo $cars[$x];
Echo “<br>”;
}
?>
</body></html>
++++++++++++++++++++++++++
32
Chapter-5
RDBMS CONCEPTS AND MYSQL
Q1. What is database?
A1. Database is a collection of inter-related data i.e composed of a collection of files that
are linked in such a way that information from one of the files may be combined with
information from other files so that user may receive the exact information. E.g.
school database organizes the data about a student, teachers and admin staff etc.
which help in efficient retrieval, insertion and deletion of data from it.
Q2. Give difference between data and information?
A2. Data : It is a raw and unorganized fact that required to be processed to make it
meaningful i.e data is the collection of raw facts and figures.
Information : The data formatted in a manner that allows it to be utilized by
human beings in some significant way i.e. processed data is called information
Q3. What is DIKW?
A3. DIKW is the model used for discussion of data, information, knowledge, wisdom and
their interrelationships. It represents structure or functional relationships between
data, information, knowledge and wisdom.
Q4. Name and explain database elements?
A4. Various database elements are :
i. Table : A table is composed of records and fields that hold data. Each
table in a database holds data about a different but related subject.
ii. Records : Data is stored in records. A record is composed of fields and
contains all the data about one particular person, company or item in a
database. Records appear as rows in the database table.
iii. Fields : A field is a part of a record and contains a single piece of data
for the subject of the record. E.g. roll_no, student_name, address etc.
iv. Instance : The collection of information stored in database at a particular
instance of time is called instance of database.
v. Schema : The overall design of the database is called database schema.
Q5. What is DBMS?
A5. DBMS : It stands for Database Management System. A DBMS is a system
software for easy, efficient and reliable data processing and management. DBMS is a
collection of inter-related data and set of programs to store and access those data in
an easy and effective manner. E.g. MySQL, Oracle etc.It can be used for :
i. Creation of a database.
ii. Retrieval of information from the database.
iii. Updating the database. iv. Managing a database.
Q6. Give various task of DBMS?
A6. Various task of DBMS are as follows :
i. Data definition : It helps in creation, modification and removal of
definitions that define the organization of data in database.
ii. Data Updation : It helps in insertion, modification and deletion of the
actual data in the database.
iii. Data Retrieval : It helps in retrieve of data from the database which can be
used by applications for various purposes.
iv. Use Administration : It helps in registering and monitoring users, enforcing
data security, monitoring performance, maintaining data integrity, dealing
with concurrency control and recovering information corrupted by unexpected
failure.
33
Q7. Name various applications where we use Database Management Systems are :
A7. Application where we use DBMS are :
i. Telecom : There is a database to keep track of the information regarding
calls made, network usage, customer details etc.
ii. Industry
iii. Banking System : For storing customer info, tracking day to day credit and
debit transactions, generating bank statements etc.
iv. Sales : To store customer information, production information and
invoice details.
iv. Airlines : To travel through airlines we make early reservations this
reservation information along with flight schedule is stored in database.
v. Education sector : Database systems are frequently used in schools, colleges.
vi. Online shopping
Q8. Name and explain components of database system?
A8. A database system is composed of following components :
i. Data : Data : It is a raw and unorganized fact that required to be processed to
make it meaningful. DBMS store and utilize data. Metadata is data about data.
E.g. When you yourName in a database, the DBMS will store when the name
was stored in the database, what is the size of the name, is it stored as related
data to some other data, or is it independent, all this information is metadata.
ii. Hardware : When we say hardware we mean computer, hard disks, I/O
channels for data and any other physical component involved before any data
is successfully stored into the memory.
iii. Software : This is the main component as this is the program which
controls everything.
iv. Data base access language :- It is a simple language designed to write
commands to access, insert, update and delete data stored in any database.
v. Users : Users are those persons who read the information from the
database to carry out their primary business responsibilities i.e. personnel,
staff, clerical etc.
Q9. What do you mean by RDBMS(Relational Database Management System)
A9. RDBMS : It stands for Relational Database management System. It is a program
that allows you to create, update and administer a relational database. It refers to a
database that stores data in a structured format using rows and columns. This makes
it easy to locate and access specific values within the database. It is “relational”
because the values within each table are related to each other. Examples of RDBMS
are : MySQL, Oracle, SQL Server etc.
Q10. What is a file system?
A10. A file system is a method for sorting and organizing computer files and the data they
contain to make it easy to find and access them.
Q11. What is traditional File System?
A11. A traditional file system is totally computer based system where all the informations
is stored in different computer files.
34
Q12. Give characteristics of traditional file processing system?
A12. The characteristics of traditional file processing system are as follows :
i. it stores data of an organization in group of files.
ii. Files carrying data are independent on each other.
iii. COBOL, C, C++ programming languages were used to design the files.
iv. Each file system contains data for some specific area or department like
library, student fees, and student examinations.
v. It is less flexible and has many limitations.
vi. it is very difficult to maintain file processing system.
vii. Any change in one file affects all the files that creates burden on the
programmer.
viii. File in traditional file processing systems are called flat files.
Q13. What are problems in traditional file oriented approach?
A13. Various problems in traditional file oriented approach are as follows :-
i. Data redundancy : It refers to the duplication of data.
ii. Data inconsistency : data redundancy leads to data inconsistency. E.g.
suppose a student is enrolled for two courses and we have student address
stored twice. Now let‟s say student requests to change his address, if address
is changed at one place and not on all the records then this can lead to data
inconsistency.
iii. Data Isolation :- Because data are scattered in various files, and files may
be in different formats, writing new application programs to retrieve the
appropriate data is difficult.
iv. Dependency on application programs : Changing files would lead to change
in application programs.
v. Atomicity issues : Atomicity of a transaction refers to “All or nothing”,
which means either all the operations in a transaction executes or none.
vi. Difficult Data Access : A user should know the exact location of file to
access data so the process is very cumbersome and tedious.
vii. Unauthorized Access : File system may lead to unauthorized access to
data. If a students gets access to file having his marks, he can change it in
unauthorized way.
viii. Concurrent Access : The access of same data by multiple users at same
time is known as concurrency. File system does not allow concurrency as data
can be accessed by one only one user at a time.
ix. No Backup and Recovery : File system does not incorporate any backup and
recovery of data if a file is lost or corrupted.
x. Data security : Data should be secured from unauthorized access.
xi. Limited data Sharing : There is limited data sharing possibilities with the
traditional file system.
35
Q14. Give difference between DBMS and Traditional File System?
A14. The difference between DBMS and Traditional File System are as follows :
i. DBMS is very expensive but, the traditional file system is cheap.
ii. DBMS is good for the large system but, the traditional file system is good
for a small system having a small number of items.
iii. DBMS Required lots of effort for designing but, the traditional file system is
very low design efforts.
iv. DBMS is highly secured but, the traditional file system is not secure.
v. DBMS is data sharable but, the traditional file system is isolated data
sharable.
vi. DBMS is flexible but, the traditional file system has a lack of flexibility and
has many limitations.
vii. DBMS has no integrity issue but, the traditional file system has an integrity
problem.
viii. DBMS has a complex backup but, the traditional file system has a simple
backup system.
Q15. Give advantages of DBMS?
A15. The various advantages of DBMS are as follows :
i. Minimal Redundancy : Data redundancy is reduced or eliminated in
DBMS because all data are stored at a centralized location rather than being
created by individual users for each application.
ii. Data Inconsistency can be avoided : In DBMS there is a single repository of
data that is defined once and is accessed by many users, and data are
consistent.
iii. Searching capability : Searching and retrieving of data is very easy in
DBMS systems.
iv. Data Sharing : DBMS allows users and applications to share data with
multiple applications and users.
v. Data Security : DBMS provide a strong framework to protect data
privacy and security.
vi. Flexibility : Database systems are more flexible than file processing systems.
vii. Data Integration : It is a process of combining the data residing at different
locations and present the user with a unified view of data.
viii. Easy access to data : A database system manages data in such a way so
that the data is easily accessible with fast response times.
ix. Concurrent access to data : Data can be accessed concurrently
by different users at same time in DBMS.
x. Data backup and recovery : DBMS provides a strong framework for
data backup and recovery.
xi. Improved decision making : Better managed data and improved data
access make it possible to generate better quality information on which better
decisions are based.
36
Q16. Give disadvantages of DBMS?
A16. The various disadvantages of DBMS are as follows :
i. DBMS requires high initial investment for hardware, software and trained staff.
ii. In order to convert our data into a database management system we need to spend a
lot which adds on to the cost of the database management system.
iii. In order to work with a Database management system a team of technical staff is
required who understand DBMS.
iv. A DBMS requires disk storage for the data and sometimes you need to purchase
extra space to store your data.
v. Database systems are complex to understand.
vi. DBMS does not give a good performance as its speed is very slow.
vii. Backup and recovery are more difficulty.
Q17. What is data abstraction?
A17. The process of hiding irrelevant details from user is called data abstraction.
Q18. Give the three types of data abstraction?
A18. The three types of data abstraction are :
i. Internal or Physical level : Actual physical storage structure and access
paths. It is physical representation of the database on the computer. This level
describes how the data is actually stored in the storage device. E.g.let‟s say we
are storing student information in a student table. At physical level these
records can be described as blocks of storage(bytes, gigabytes etc.) in
memory.
ii. Conceptual or Logical Level : Structure And constraints for the entire
database. The whole design of the database such as relationship among data,
schema of data etc are described in this level. At the logical level records can
be described as fields and attributes along their data types, their relationship
among each other.
iii. External or view level : Describes various user views. At view level, user
just interact with system with help of GUI and enter the details at the screen,
they are not aware of how the data is stored and what the data is stored, such
details are hidden from them.
Q19. Name three types of users for a DBMS?
A19. The three types of users for a DBMS are :
i. The Application Programmer : These users write application programs to
interact with the database.
ii. The End User : End users are the users, who use the applications
developed. End users are of two types :
a. Direct user : They are the users who see the computer, database
system directly, by following instructions provided in the user interface.
b. Indirect users : They are the users just concerned with the output and are
not bothered about the programming part.
iii. System Analyst : System Analyst determines the requirement of end users,
database designing, feasibility, economic, technical aspect of the system.
Q20. What do you mean by DBA?
A20. DBA : It stands for Database Administrator. DBA is the person which makes the
strategic and policy decisions regarding the data of the enterprise, and who provides
the necessary technical support for implementing these decisions. DBA is
responsible for designing, implementing and maintaining database, use of database
management system and training employees in database management etc.
37
Q21. What is the role of DBA?
A21. The role of the DBA is very important and is defined by the following functions :
i. Schema definition : The DBA defines the logical schema of the database.
According to this schema, database will be developed to store required data
for an organization.
ii. Storage structure and access method definition : The DBA decides how
the data is to be represented in the stored database.
iii. Assisting application programmers : The DBA provides assistance to
application programmers to develop application programs.
iv. Physical Organization Modification : The DBA modifies the physical
organization of the database to reflect the changing needs of the organization
or to improve performance.
v. Approving Data Access : The DBA determines which user needs access to
which part of the database.
vi. Liaising with users : The DBA needs to interact continuously with the
users to understand the data in the system and its use.
vii. Monitoring Performance : The DBA monitors performance of the
system.
viii. Backup and Recovery : Database should not be lost or damaged.
Q22. Write a note on Data Dictionary?
A22. A data dictionary contains metadata i.e. data about the database. It is a dictionary
about the data that we store in the database. It contains all the information about the
data objects such as :
i. Names of all the database tables and their schemas.
ii. Details about all the tables in the database such as their owners, their
security constraints, when they were created etc.
iii. Physical information about the tables such as where they are stored and how.
iv. Table constraints such as primary key attributes, foreign key information etc.
v. Information about the views of the database.
vi. It also contains the physical information of the table like about their storage,
about their alteration etc.
Q23. Name and explain two types of data dictionary?
A23. The two types of data dictionary is :
i. Active Data Dictionary : Any changes to the database object structure via
DDLs will have to be reflected in the data dictionary. But updating the data
dictionary tables for the changes are responsibility of database in which the
data dictionary exists. If the data dictionary is created in the same database,
then the DBMS software will automatically update the data dictionary. Hence
there will not be any mismatch between the actual structure and the data
dictionary details. Such data dictionary is called active data dictionary.
ii. Passive Data Dictionary : In some of the databases, data dictionary is created
separately from the current database as entirely new database to store only
data dictionary information. Sometimes it is stored as XML, excels or in any
other file format. In such case, an effort is required to keep data dictionary in
sync with the database objects. This kind of data dictionary is called passive
data dictionary.
38
Q24. What is integrity constraints?
A24. Database integrity refers to the validity and consistency of stored data. Integrity is
usually expressed in terms of constraints, which are consistency rules that the
database is not permitted to violate. Integrity constraints are a set of rules. It is used
to maintain the quality of information. It ensure that the data insertion, updating and
other processes have to be performed in such a way that data integrity is not affected.
It is used to guard against accidental damage to the database. E.g. A blood group
must be „A‟, or „B‟ or „AB‟ or „O‟ only but cannot be of any other values
39
Q27. Name various type of data types used in DBMS?
A27. In SQL there are three main data type :
i. Numeric : Numeric data types are normally used to store numeric data like
age, marks, salary etc. Numeric datatypes are following :
a. Int : used for number without decimal
b. Decimal(m,d) : used for floating/real numbers.
Here m denotes the total length of number and d is number of decimal
digits.
ii. Date and Time :
a. Date : used to store date in YYYY-MM-DD format e.g date of birth,
purchase date etc.
b. Time : used to store time in HH:MM:SS format e.g arrival time,
departure time etc.
iii. String type : These are used to store names , addresses, descriptions or any
value that contains letters and numbers including binary data, like image or
audio files. String datatypes are following :
a. Char(n) : used to store a fixed length string.
b. Varchar(n) : used to store a variable length string. Here n denotes
maximum number of characters.
40
Q30. Give characteristics of SQL?
A30. The various characteristics of SQL are as follows :
i. SQL is used for storing and managing data in relational database management
system(RDBMS)
ii. All the RDBMS like MySql, Oracle, MS Access and SQL server use SQL as
their standard database language.
iii. SQL allows users to query the database in a number of ways, using English-
like statements.
iv. SQL is used to perform create, retrieve, update and delete operations on
relational database.
v. It can also perform administrative tasks on database such as database security,
backup, user management etc.
vi. We can create databases and tables inside database using SQL.
vii. It is not case sensitive.
viii. Statements of SQL are dependent on text lines. We can use a single SQL
statement on one or multiple text line.
ix. Using the SQL statements, you can perform most of the actions in a database.
x. SQL depends on tuple relational calculus and relational algebra.
Q31. What are SQL commands?
A31. SQL commands are instruction, coded into SQL statement which are used to
communicate with the database to perform specific tasks, work, functions and
queries with data. SQL commands are grouped into four major categories depending
on their functionality namely Data Definition Language(DDL), Data Manipulation
Language(DML), Transaction Control Language(TCL), Data Control
Language(DCL).
41
Q34. How will you create a table?
A34. To create table we use CREATE TABLE statement.
Syntax is :
CREATE TABLE table_name
(
Column1 data_type(size),
Column2 data_type(size),
Column3 data_type(size),
……….
……….
);
Example is :
CREATE TABLE student
(
ROLLNO int(3),
STUDENTNAME varchar(30),
ADDRESS varchar(30),
PHONENO int(12),
AGE int(12)
);
For example : to delete all the rows from student table, the query would be like
TRUNCATE TABLE student.
42
Q37. Write note on DML ?
A37. DML(Data Manipulation Language) : These commands are used for storing,
retrieving, modifying and deleting data.
Examples of DML are :
i. SELECT : is used to retrieve data from the database.
ii. INSERT : is used to insert data into a table.
iii. UPDATE : is used to update existing data within a table.
iv. DELETE : is used to delete records from a database table.
43
Q40. Write a note on WHERE clause?
A40. WHERE clause is used with SELECT statement to specify the condition based on
which rows will be extracted from the table. It is used to fetch data according to a
particular criteria.
Syntax:
SELECT column1, column2 FROM table_name WHERE column_name operator
value;
Example :
i. Write a query to fetch records of students from student table with age
equal to 20?
SELECT * FROM Student WHERE AGE=20;
ii. Write a query to fetch Name and Address of students from tha table student
with ROLL_NO greater than 3?
SELECT ROLL_NO , NAME , ADDRESS FROM Student WHERE
ROLL_NO>3;
Q41. Write a note on BETWEEN operator?
A41. The BETWEEN operator is used to specify a range of values. The range you specify
contains a lower and upper range. It is used to fetch filtered data in a given range
inclusive of two values.
Syntax :
SELECT column1, column2 FROM table_name WHERE column_name BETWEEN
value1 AND value2;
Where :
Between is the operator name
Value1 and value2 : are the exact value from value1 to value2 to get related data in
result set.
Example :
I. Write a query to fetch records of students from Student table where
ROLL_NO is between 1 and 3 (inclusive).
SELECT * FROM Student WHERE ROLL_NO BETWEEN 1 AND 3;
II. Write a query to fetch NAME, ADDRESS of students where AGE is between
20 and 30(inclusive).
SELECT NAEM, ADDRESS FROM Student WHERE AGE BETWEEN 20
AND 30;
Q42. Write a note on LIKE operator?
A42. LIKE operator is used to fetch filtered data by searching for a particular pattern in
WHERE clause. LIKE operator is used with CHAR datatype.
Syntax :
SELECT column1, column2 FROM table_name WHERE column_name LIKE
pattern;
Example :
i. Write a query to fetch records of students from Student table where NAME
starts with letter S?
SELECT * FROM Students WHERE NAME LIKE „S%‟;
ii. Write a query to fetch records of students from Student table where NAME
contains the pattern „AM‟?
SELECT * FROM Student WHERE LIKE „%AM%‟;
44
Q43. Write a note on IN operator?
A43. IN operator is used to fetch filtered data same as fetched by „=‟ operator just the
difference is that here you can specify multiple values for which we can get the result
set.
Syntax :
SELECT column1, column2 FROM table_name where
column_nameIN(value1, value2, value3, ….)
Example :
I. Write a query to fetch NAME and ADDRESS of students from table Student
where Age is 18 or 20?
SELECT NAME, ADDRESS FROM Student WHERE AGE IN(18,20);
II. Write a query to fetch records of students from table Student where
ROLL_NO is 1 or 4?
SELECT * FROM Student WHERE ROLL_NO IN(1,4);
Q44. Write a note on AND operator?
A44. AND operator is used to displays only those records where both the conditions
condition1 and condition2 evaluates to True.
Syntax :
SELECT * FROM table_name WHERE condition1 AND condition2 and …..
condition;
Example :
i. Write a query to fetch all records from student table where AGE is 18 and
ADDRESS is DELHI?
SELECT * FROM Student WHERE AGE = 18 AND ADDRESS = „DELHI‟;
ii. Write a query to fetch all the records from Student table where NAME is Ram
and age is 18?
SELECT * FROM Student WHERE AGE = 18 AND NAME = „RAM‟;
46
Q52. What do you mean by Alias? How will you define column Alias?
A52. Alias are the temporary names given to table or column for the purpose of a
particular SQL query.
Syntax :
SELECT column as Alias_name FROM table_name;
Example :
Write a query to fetch ROLL_NO, NAME from Student table using S_CODE,
S_NAME as alias name respectively?
SELECT ROLL_NO As S_CODE , NAME AS S_NAME FROM student;
Q53. What is Transaction?
A53. Transaction is a group of a set of tasks into a single execution unit. Each transaction
begins with a specific task and ends when all the tasks in the group successfully
complete. A transaction has only two results : success or failure.
Q54. Write note on TCL?
A54. TCL(Transaction Control Language) : These commands are used for managing
changes affecting the data. Examples of TCL commands are :
i. COMMIT : it commits a transaction. It is used for storing changes
performed by a transaction. When a COMMIT command is issued it saves all
the changes since last COMMIT or ROLLBACK.
Syntax :
COMMIT;
Example :
Write a query which would delete those records from the table which
have age = 20 and then COMMIT the changes in the database?
DELETE FROM Student WHERE AGE =20;
COMMIT;
48
Q58. What is Constraints? Name and explain most commonly used constraints
available in MYSQL?
A58. Constraints are the rules enforced on the data columns of a table. These are used to
limit the type of data that can go into a table. This ensures the accuracy and
reliability of the data in the database.
The following are some of the commonly used constraints available in MYSQL :
i. NOT NULL constraint : It ensures that a column cannot have NULL vale.
ii. DEFAULT constraint : It provides a default value for a column when none is
specified.
iii. UNIQUE constraint : It ensures that all values in a column are different.
iv. PRIMARY KEY : It uniquely identifies each row/record in a database table.
v. FOREIGN KEY : It uniquely identifies a row/record in any of the given
database table.
vi. CHECK constraint : It ensures that all the values in a column satisfies certain
conditions.
49
Q61. Name and explain various types of keys used in RDBMS systems?
A61. The various types of keys used in RDBMS systems are :
i. Candidate Key : Candidate key is a key of a table which can be selected as a
primary key of the table. A table can have multiple candidate keys out of
which one can be selected as a primary key.
ii. Primary key : It is a candidate key of the table selected to identify each record
uniquely in table. Primary key does not allow null value in the column and
keeps unique values throughout the column.
iii. Unique key : It is similar to primary key and does not allow duplicate values
in the column. The difference between primary key and unique key is that it
allows one null value in the column.
iv. Alternate key : It is a candidate key, currently not selected as primary key of
the table.
v. Composite key : It is a group of two or more columns that identifies each row
of a table uniquely.
vi. Super key : It is a set of columns on which all columns of the table are
functionally dependent. It is a set of columns that uniquely identifies each row
in a table.
vii. Foreign key: In a relationship between two tables a primary key of one table is
referred as a foreign key in another table.
Q62. Give difference between Primary and Candidate Key?
A62. The difference between Primary and Candidate key are :
51
iv. LEN( ) : This function returns the length of the value in a text field.
Syntax : SELECT LENGTH(column_name) FROM table_name;
Example : Write a query to fetch the length of names of students from
Marks table?
SELECT LENGTH(NAME) FROM Marks;
52
Chapter-6
PL/SQL
Q1. What do you mean by PL/SQL?
A1. PL/SQL is a block structured language that enables developers to combine the power
of SQL with procedural statement. The architecture of PL/SQL mainly consists of
following three components :
i. PL/SQL block
ii. PL/SQL engine
iii. Database Server
Q2. Give features of PL/SQL?
A2. The features of PL/SQL are as follows :
i. PL/SQL is basically a procedural language which provides the functionality of
decision making, iteration and many more features of procedural
programming languages.
ii. PL/SQL can execute a number of queries in one block using single command.
iii. One can create a PL/SQL unit such as procedures, functions, packages,
triggers.
iv. PL/SQL provides a feature to handle the exception which occurs in PL/SQL
block known as exception handling block.
v. Applications written in PL/SQL are portable to computer hardware or
operating system where Oracle is operational.
vi. PL/SQL offers extensive error checking.
Q3. Give advantages of using PL/SQL?
A3. The advantages of using PL/SQL are as follows :
i. Better performance as sql is executed in bulk rather than a single statement.
ii. High Productivity.
iii. Tight integration with SQL.
iv. Full Portability.
v. Tight Security
vi. Support Object Oriented Programming concepts.
Q4. What are the disadvantages of SQL? Explain.
A4. The disadvantages of SQL are as follows :-
i. SQL does not have procedural capabilities i.e SQL does not provide
programming techniques of conditional checking, looping and branching that
is vital for data testing storage.
ii. SQL statements are passed to the Oracle engine one at a time. Each time an
SQL statement is executed, call is made to the engine‟s resources. This adds
to the traffic on the network, thereby decreasing the speed of data processing,
especially in a multiuser environment.
iii. While processing an SQL sentence if an error occur the ORACLE engine
displays its own error messages. SQL has no facility for programmed handling
of errors that arise during manipulations of data.
53
Q5. Give the PL/SQL block structure?
A5. PL/SQL programs are made up of blocks. The block has the following structure :
i. DECLARE
This section begins with DECLARE keyword in which
variables, constants, records as cursors can be declared which
stores data temporarily. It contains definition of PL/SQL
identifiers. This part of the code is optional.
ii. BEGIN
This section is mandatory section and here the program logic is written
to perform any task like loops and conditional statements. It supports
all DML commands, DDL command and SQL*Plus built-in functions
as well.
iii. EXCEPTIONS
This section starts with EXCEPTION keyword. This section is optional
which contains statements that are executed when a run time error
occurs.
iv. END;
Q6. Give difference between SQL and PL/SQL?
A6. The difference between SQL and PL/SQL are as follows :
SQL PL/SQL
1. No Procedural Capabilities : 1. Procedural Capabilites :
SQL does not have procedural PL/SQL is basically a procedural language
capabilities i.e SQL does not which provides the functionality of
provide programming techniques decision making, iteration and many more
of conditional checking, looping features of procedural programming
and branching that is vital for data languages.
testing storage.
2. Time Consuming Processing : 2. Reduced Network Traffic :
SQL statements are passed to the PL/SQL statements sends an entire block of
Oracle engine one at a time. Each statements at one time. This reduces network
time an SQL statement is executed, time considerably.
call is made to the engine‟s
resources. This adds to the traffic
on the network, thereby decreasing
the speed of data processing,
especially in a multiuser
environment.
3. No Error handling Procedures : 3. Error handling Procedures :
While processing an SQL sentence PL/SQL offers extensive error checking.
if an error occur the ORACLE
engine displays its own error
messages. SQL has no facility for
programmed handling of errors that
arise during manipulations of data.
4. No facilities sharing : 4. Facilities Sharing :
SQL does not allow sharing of PL/SQL provides access and sharing of same
facilities. subprogram by multiple applications.
54
Q7. Name various PL/SQL identifiers?
A7. The various PL/SQL identifiers are variables, constants, procedures, cursors, triggers
etc.
Q8. What do you mean by variable?
A8. A variable is a name associated with value. A variable stores or contains the value.
Variables allow you to store and manipulate data in program. It can hold any value
during the execution of the program.
Syntax is :
Variablenamedatatype [NOT NULL := value];
Example :
Write a program to show how to declare variable in PL/SQL?
SQL> SET SERVEROUTOUT ON ;
SQL> DECLARE
var1 INTEGER;
var2 REAL;
var3 varchar2(20);
BEGIN
Null;
END;
/
Q9. What is IF statements ?
A9. The IF statement executes a sequence of statements depending on the value of a
condition. There are three forms of IF statements :
i. IF-THEN
In this form the sequence of statements is executed only if the
condition is TRUE. If the condition is FALSE or NULL, the IF
statement does nothing. In either case control passes to the next
statement.
Syntax :
IF <condition> THEN
<Action>
END IF;
Example :
Write a program in PL/SQL to check the given value is greater
than 50 by using IF-THEN statement?
DECLARE
a NUMBER :=60;
BEGIN
dbms_output.put_line(„Program started.‟);
IF(a >50) THEN
dbms_output.put_line(„ a is greater than 50.‟);
END IF;
dbms_output.put_line(„Program completed.‟);
END;
/
Output :
a is greater than 50.
55
ii. IF-THEN-ELSE :
This form is used when you want to choose between two
mutually exclusive actions.
Syntax :
IF condition THEN
Sequence of executable statements;
ELSE
Sequence of executable statements;
END IF;
Example :
Write a program in PL/SQL to check the given value is greater
or less than 50 by using IF-THEN-ELSE statement?
DECLARE
a NUMBER :=30;
BEGIN
dbms_output.put_line(„Program started.‟);
IF(a >50) THEN
dbms_output.put_line(„ a is greater than 50.‟);
ELSE
dbms_output.put_line(„ a is less than 50.‟);
END IF;
dbms_output.put_line(„Program completed.‟);
END;
/
Output :
a is less than 50.
56
iii. IF-THEN-ELSEIF :
The IF-ELDEIF formulation provides a way to handle
multiple conditions within a single IF statement.
Syntax :
IF condiont-1 THEN
Statements-1;
ELSEIF condition-2 THEN
Statement-2;
[ELSE
Statement-3]
END IF;
Example :
Write a program in PL/SQL to display value of variable by
using IF-THEN-ELSEIF statement.
DECLARE
a NUMBER(3) :=60;
BEGIN
dbms_output.put_line(„Program started.‟);
IF(a = 10) THEN
dbms_output.put_line(„ Value of a is 10.‟);
ELSEIF (a = 20) THEN
dbms_output.put_line(„Value of a is 20.‟);
ELSEIF ( a = 30) THEN
dbms_output.put_line(„Value of a is 30.‟);
ELSE
dbms_output.put_line(„None of the values is matching.‟);
END IF;
dbms_output.put_line(„Exact value of a is : „ | | a);
END;
/
Output :
None of the value is matching.
Exact value of a is :60
Q10. Write a note on LOOP statements/Iterative control?
A10. LOOP statements/Iterative control executes a sequence of statements multiple times
or indicates the ability to repeat or skip sections of a code block. A loop marks a
sequence of statements that has to be repeated. The keyword loop has to be placed
before the first statement in the sequence of statements to be repeated, while the
keyword end loop is placed immediately after the last statement in the sequence.
Types of LOOP in PL/SQlare :
i. Basic loop statement ii. For loop statement iii. While loop statement
57
Q11. Explain the BASIC LOOP Statement?
A11. The BASIC LOOP statement execution block starts with keyword „LOOP‟ and ends
with the keyword „END LOOP‟ which encloses a sequence of statements between
the keywords LOOP and END LOOP.
Syntax :
LOOP
Sequence of statements;
END LOOP;
Example :
Write a program in PL/SQL to print number from 1 to 5 using basic loop
statement?
1. DECLARE
2. a NUMBER := 1;
3. BEGIN
4. dbms_output.put_line(„Program started :‟);
5. LOOP
6. dbms_output.put_line(„ a ‟);
7. a := a + 1;
8. EXIT WHEN a > 5;
9. END LOOP;
10. dbms_output.put_line(„Program completed.‟);
11. END;
12. /
Output :
Program started :
1
2
3
4
5
Program completed.
58
Q12. Explain the FOR LOOP statement?
A12. FOR LOOP iterate over a specified range of integers. The number of iterations is
known before the loop is entered. A double dot (..) serves as the range operator. In
this loop, the lower limit and the upper limit will be specified and as long as the loop
variable is in between this range, the loop will be executed.
Syntax :
FOR <loop variable> IN <lower_limit> ..<upper_limit>
LOOP
Execution block starts
.
.
Execution block end
END LOOP;
Example :
Write a program in PL/SQL code to print number from 1 to 5 using FOR loop
statement ?
1. BEGIN
2. dbms_output.put_line(„Program started :‟);
3. FOR a IN 1 . . 5
4. dbms_output.put_line(a);
5. END LOOP;
6. dbms_output.put_line(„Program completed.‟);
7. END;
8. /
Output :
Program started :
1
2
3
4
5
Program completed.
59
Q13. Explain WHILE LOOP statement?
A13. WHILE loop statements works similar to the BASIC LOOP statement except the
EXIT condition is at the very beginning of the loop. It works like an entry-check loop
in which execution block will not even be executed once if the condition is not
satisfied.
Syntax :
WHILE <EXIT condition>
LOOP
Execution statements;
.
.
END LOOP;
Example :
Write a program in PL/SQL code to print number from 1 to 5 using
WHILE loop statement ?
1. DECLARE
2. a NUMBER := 1;
3. BEGIN
4. dbms_output.put_line(„Program started :‟);
5. WHILE( a < 5)
6. LOOP
7. dbms_output.put_line(a);
8. a := a + 1;
9. END LOOP;
10. dbms_output.put_line(„Program completed.‟);
11. END;
12. /
Output :
Program started :
1
2
3
4
5
Program completed.
60
Q15. Give benefits of triggers?
A15. The benefits are as follows :
i. Generating some derived column values automatically.
ii. Enforcing referential integrity.
iii. Event logging and storing information on table access.
iv. Auditing.
v. Synchronous replication of tables.
vi. Imposing security authorizations.
vii. Preventing invalid transactions.
Q16. Give different types of triggers in PL/SQL?
A16. The different types of triggers are :
i. ROW LEVEL TRIGGERS and STATEMENT LEVEL TRIGGERS :
A statement level trigger is fired once on behalf of the triggering statement,
regardless of the number of rows in the table that the triggering statement
affects. A row trigger fires once for each row affected by the triggering event.
ii. BEFORE and AFTER TRIGGERS :
BEFORE trigger run the trigger action before triggering statement is run.
BEFORE trigger execute before the triggering DML statement(INSERT,
UPDATE, DELETE) execute. AFTER triggers run the trigger action after the
triggering statement is run. AFTER trigger execute after the triggering DML
statement (INSERT, UPDATE, DELETE) executed.
iii. INSTEAD OF TRIGGERS :
INSTEAD of triggers describe how to perform insert, update and delete
operations against views that are too complex to support these operations
natively.
Q17. What do you mean by cursor?
A17. We can manipulate within a SQL statement by means of assigning a name to a
“select statement”, this concept is known as cursor. It is used for processing
individual rows returned as a result for a query. It is the work area which Oracle
reserves for internal processing of SQL statements.
Q18. Name the types of cursors?
A18. There are two types of cursors :
i. IMPLICIT CURSORS :
This type of cursors are automatically created by PL/SQL whenever an SQL
statement is executed. Whenever a DML statement(INSERT, UPDATE and
DELETE) is issued an implicit cursor is associated with this statement.
ii. EXPLICIT CURSORS :
This type of cursors are defined by the programmers to gain more control over
the context area. These cursors should be defined in the declaration section of
the PL/SQL block. It is created on a SELECT statement which returns more
than one row.
61
Q19. Give the attributes of implicit cursors?
A19. The different attributes of implicit cursor are :
Attribute Description
%FOUND Returns TRUE if an INSERT, UPDATE, or DELETE statement affected
one or more rows or a SELECT INTO statement returned one or more
rows. Otherwise it returns FALSE.
%NOTFOUND The logical opposite of %FOUND. It returns TRUE if an INSERT,
UPDATE, or DELETE statement affected no rows or a SELECT INTO
statement returned no rows. Otherwise it returns FALSE.
%ISOPEN Always returns FALSE for implicit cursors, because Oracle closes the
SQL cursor automatically after executing its associated SQL statement.
%ROWCOUNT Returns the number of rows affected by an INSERT, UPDATE or
DELETE statement or returned by a SELECT INTO statement.
62
Chapter-7
Internet Business Application
63
Q5. Give features of e-commerce?
A5. The features of e-commerce are as follows :
i. Non-Cash Payment: e-commerce enables use of credit cards, debits cards,
smart cards and other modes of electronics payment.
ii. 24 x 7 service availability : e-commerce automates business of enterprises and
services provided by them to customers are available anytime, anywhere.
iii. Advertising/Marketing : e-commerce increases the reach of advertising of
products and services of business.
iv. Improved Sales : Using e-commerce, orders for the products can be generated
any time, any where without any human intervention.
64
Q8. What is Net banking? Give its advantage and disadvantage?
A8. Net Banking is the process of conducting banking transactions over the internet. It
enables bank customers to handle account management and perform account
transactions directly with the bank through the internet.
Advantages of Net Banking are as follows :
i. An online account is simple to open and easy to operate.
ii. It‟s convenient
iii. You do not have to stand in a queue to pay off your bills.
iv. It is available all the time.
v. It is fast and efficient
vi. You can keep an eye on your transactions and account balance all the time.
Disadvantages of net banking are as follows :
i. Understanding the usage of internet banking might be difficult for a beginner.
ii. Security of transactions is a big issue.
iii. Password security is a must.
iv. If the banker‟s server is down then you cannot access your accounts.
v. You cannot have access to online banking if you don‟t have an internet
connection.
Q9. Give various modes of online payment?
A9. Various mode of online payments are : Credit Card, Debit Card, Smart Card, E-
money, Electronic Fund Transfer(EFT)
Q10. What is online reservation? Give it’s advantages and disadvantages?
A10. Online reservation is a method which helps the travel and tourism industry support
reservation through internet. It helps consumer to book flights, hotels, holiday
packages, insurance and other online services.
Advantages of online booking system are as follows :
1. Its quicker and easier to book online.
2. Most airlines usually offer incentives for cheaper flights if you book online.
3. Booking online means that its easy to track prices.
4. Large choice of hotels, tickets and easy to use interface and search engines.
5. Immediate confirmation as per system announcement.
Disadvantages of online booking system are as follows :
1. It can sometimes be hard to find a real bargain when surfing the web.
2. A computer crash could cause a passenger‟s reservation and other information to
simply vanish.
3. For online booking a well designed website needs to be put in place along with a
database.
4. You can make a mistake and book the wrong seats.
5. If the server is down or running very slowly, then much business can be lost and
annoy a lot of customers.
65
Q11. What is customer support services? Give its advantages and disadvantages?
A11. Customer Service means range of services provided to assist customers in making
cost effective and correct use of a product. It includes assistance in planning,
installation, training, trouble shooting etc.
Advantages of customer support services are as follows :
1. You can reach out at the right time to provide pre-sale and post-sale support.
2. It is quicker and easy.
3. Complaints can be submitted very easily filled 24 x 7.
4. It provides high level of satisfaction.
5. It saves time and money.
Disadvantages are as follows :
1. Some software is priced out of reach and takes a while to get used to.
2. Some software is difficult to get used to.
3. Need trained manpower.
Q12. What is online marketing and shopping? Give its advantages and
disadvantages?
A12. The act of purchasing products or services over the internet is known as online
shopping. Internet marketing refers to advertising and marketing efforts that use the
web and email to drive direct sales via electronic commerce which allows consumers
to directly buy goods or services from a seller over internet.
Advantages of shopping online are as follows :
1. It has more variety and better prices.
2. Easy to send gifts.
3. Easy price comparisons.
4. No sales pressure.
5. Access to used or damaged inventory.
Disadvantages are as follows :
1. Shipping problems and delays.
2. Risk of fraud.
3. Less contact with your community.
4. Returns can be complicated.
5. No sales assistance.
6. No support for local retailers.
Q13. What is social networking? Give its advantages and disadvantages?
A13. Social networking is the use of internet based social media programs to make
connections with friends, family, classmates, customers and clients.
Advantages of social networking are as follows :
1. Social networking has decreased the distance between friends and relatives.
2. These have increased the strength of relationships between friends and some
distant relatives.
3. These will provide opportunity to increase the communication skills as the person
is not infront of you one can talk freely.
4. One can know the updates of his friends, even without talking with them
personally.
5. One can make their ideas reach thousands of people with their posts thus
becoming popular.
6. Social networking sites are free to download.
66
Disadvantages of social networking are as follows :
1. There is a possibility of committing fraud and send spam messages.
2. Wastage of time.
3. Many people pretend to be someone else and prepare their online profiles with
false information.
Q14. Give examples of social networks?
A14. Various examples of social networks are as follows :
1. Bebo: A popular social networking site where people can share photo‟s,
stories, their journal etc with their friends and family privately or publicly on
the internet.
2. Facebook: It is a popular destination for users to setup their own personal
web pages, connect with friends, share pictures, movies, talk about what you
are doing etc.
3. Google+ : The latest social networking service from google.
4. Twitter : Another fantastic service that allows users to post 140 character
long posts from their phones and on the internet.
5. Youtube : A great network of users posting video blogs and other fun and
interesting videos.
67