Computer Tybcom - 241111 - 133608
Computer Tybcom - 241111 - 133608
DATA COMMUNICATIONS
The communication of Data includes sharing or transferring Data from one end to other end. The
data can be the form of text ,numbers, audio, images or videos. In Networking it implies exchange
of data between two devices via some form of transmission medium. The communication requires
a system which is made up of hardware and software.
Thus Data Communication consist of exchange of information in the form of different types of data
from one point (sender) to another point (receiver) and vice versa. The purpose is not only to
transfer a message but also to ensure that message reaches proper destination, in a timely manner
and with the required effect.
The Efficiency of data communication system depends on the following four basic characteristics.
CHARACTERISTICS
Delivery : The system must deliver the data to the correct specified destination. The
destination can be single or multiple in number.
Accuracy : The data must be delivered accurately. That is, the system isn’t allowed to make
any changes, variations in the data. Suppose, these are alterations, it should result in an
error.
Timelines : The data must be delivered at specified exact time to the destination. If the data
isn’t delivered on time, sometimes it becomes useless or redundant at the receiver’s end.
For example if daily balances at different branches of a bank are to be reported to the head
office everyday sat before 4.00 p.m, then it will be useful to head office, only when it
reaches it, within the stipulated time.
Jitter : It refers to the fluctuations in the arrival time of packets, especially while delivery is
of audio or video packets. There should not be Jitters or variations in Data communication.
COMPONENTS
The following are five components of Data communication System. These include the Sender, the
Receiver, the Message , the Transmission Medium and the Protocol. Let us learn more about
them.
Sender : The Sender is a devise used to send the data message. It may be a computer, work
station, Telephone Handset, Video camera, Mobile, radio and so on.
Receiver : The Receiver is a device used to receive the message. It can be computer,
workstation, Telephone Handset, Television and so on.
Message : The Message consists of the data or information to be communicated.
It can be in the form of text, numerals, images, audio, and video.
Transmission Medium : The Transmission Medium refers to the physical path through
which data travels from sender’s end to receiver’s end. Some of the commonly used media,
for Data transmission are twisted pair wires, coaxial cables, fibre-optic cables and radio
waves.
Protocol : A Protocol refers to set of rules that govern communication of data.
Communication is not possible without a Protocol. The TCP/ IP Protocol is widely used in
Internet and is framework for developing a complete range of computer communication
statndards.
Now let us study different ways in which Data is reprented.
DATA REPRESENTATION
The information or data can be in terms of Text, Numbers, Images, Audios and Videos.
Text : The Text is represented as a Bit (Binary Digit ) pattern, i.e a sequence of 0 ( zero) and l
(one) digits. There are many ways of representing text symbol in a code. The current coding
system, Unicode, uses 32 bits to represents a symbol or character used in any language in
the world, which contains the popular ASCII code (American Standard Code for Information
Interchange) as first l27 characters.
Numbers : The Numbers are also represented by bit pattern. Note that ASCII codes are not
used but a number is directly converted into binary digit e.g. the number 23 is represented
as l0lll in Binary.
Images : The Images are represented by bit pattern. An image is composed of a matrix,
consisting of small dots known as Pixels. The size and number of pixels in an Image depends
on the resolution. e.g. an image can be divided into l000 pixels or l0,000 pixels as well.More
Pixels lead to better Resolution with a better Presentation of Image. At the same time, more
Pixels require more Memory to store the image.
Audio : It refers to data represented as recording or broadcasting of sound or music. The
data is in a continuous form, not like earlier types. Data communication, it is changed to a
digital or an analog signal.
Video : It refers to data type consisting of recording or broadcasting of a picture or a
movie. It can be produced in the continuous form as a continuous entity with the help of a
medium like a T.V. camera. It can also be requested as a combination of Images, each, a
discrete entity, but the combination or arrangement gives idea of motion. The video data is
changed to a digital or an analog signal.
After studying the various data types, let us consider the concept of Distributed Processing, in
networks while communicating data.
DISTRIBUTED PROCESSING
In Data Communication, data is transferred with the help of Networks of Computers, connected by
Communication Links. The network may consist of, not only computers but any other input-output
device as well like a printer. These are called as Nodes, which can be any device capable of sending/
receiving data from other nodes of the network.
The transmission of Data in Networks is mostly carried out with the help of Distributed Processing,
the tasks or functions are divided among many computers. There are separate computers, usually
P.C.S. to handle a subset of processing. There are many Independent Computers, with their own
local memory which deal with different aspects of Processing. These autonomous computers can
communicate with each other by passing the message.
A Distributed Processing system is more efficient than a single large machine handling all aspects of
Processing.
NETWORK BASICS AND INFRASTRUCTURE
We know that Network is a group of computers and other peripheral devices like printers, scanners,
which are connected by a communication link. All computers in a network are connected to each
other, to enable them to share applications, data and hardware components.
The networks can be divided into different types according to the transmission medium, according
to their size, architecture, structure, etc. Let us consider different types of Network, classified
according to their size like LAN, MAN and WAN.
TYPES OF NETWORK
LAN (Local Area Network)
It is a network restricted to a Limited geographical location. The LAN is usually located
within a single building or a campus of upto a few kilometers in size, like offices of
companies, banks, educational institutions, etc.
It is used to connect various terminals, in different departments to facilitate sharing of data
resources, peripherals, etc.
It increases memory of each terminal, providing alternative sources of supply.
The terminals or nodes (workstations) are connected to the network File Server which is
sometimes referred as Network driver. In some LAN systems, there are special servers like
network print servers, communication servers, fax servers, etc.
The file server stores the required data, and provides it to the workstations or nodes, on
request.
The resources like software packages, data-storage devices, hardware, etc. are shared by all
nodes.
Sharing of Resources increases efficiency of network by helping in quick decision making
and by reducing the cost.
The limited or restricted area of LAN helps in easy and quick location of faults and thus delay
in results is decreased.
The workstations are physically connected with the help of wire or cable.
The nodes/ workstations are physically arranged using topologies such as Star, Bus, Ring
(which will be discussed later in the chapter).
The data transfer speed is in megabytes per second. The early LAN networks had the rates in
the range 4 to l6 mbps. However, now-a- days speed is l00 to l000 mbps.
MAN (Metropolitan Area Network
It is a Network, covering the area of 40-60 kms inside a city. It is used in companies requiring
a high speed connectivity.
It is a larger version of LAN and it uses a similar technology.
An example of a MAN network is a special part of telephone company network (like MTNL),
which provide high speed DSL (Digital Subscriber Line ) Line to customers or a cable T.V.
network, which, now-a-days, is used for high-speed data connection to Internet.
A MAN can provide and support data as well as voice signals.
It is a bigger network than LAN, where micro computers or nodes or workstations are
physically connected using fiber optic cable.
Usually MAN contains more than one file server which manages sharing of resources like
printers, data storage devices, software’s, etc.
In MAN networks, the data transfer speed is around 20 mbps.
LAN can be connected to MAN and two or more MAN networks can be connected to each
other using Bridges and Gateways.
WAN (Wide Area Network)
It is a much larger Network than LAN, covering a vast geographical area, often a country or a
continent.
It is a collection of host machines, connected by a communication subnet.
In most WAN systems, the subnet consists of components like Transmission media (also
called as circuits, channels) and the switching elements which are also called as packet-
switching nodes, intermediate nodes or routers.
The switched WAN connects the end systems, which mostly consists of a Router which
connects to another WAZN or LAN.
The point to point WAN consists of leased line from a telephone company or a cable T.V.
provider. It is used to connect a small LAN to an ISP (Internet service provider).
Examples of WAN are ATM network (Asynchronous Transfer Mode). Now-a-days wireless
WAN network are also used.
In WAN also, sharing of resources, data, more than one file servers, etc. are used.
The data transfer speed is around 55 kbps
The working of WAN is based on following:
1. The data is moved by transmission line in bits or packets between the machine lines.
2. When the data is arrived at a router, it selects an outgoing line to forward it to required
router.
3. It may be sent via one or more intermediate routers, in which it is stored until the
required output line is free and then forwarded.
4. A subnet, using this principle is called a Point-to-point, store and forward or packet-
switched subnet
NETWORK STRUCTURES
The Networks can be divided according to their Architecture like server based, client/ server, peer
to peer, etc. the type are categorized by the roles the servers and nodes (computer) play, in terms
of hierarchical and security interaction. Let us study them in detail.
Served Based Networks
In theses network, there are many nodes and one or more servers. The servers control the access
to resources for user nodes. Each node can access the file on the server but not files on the other
nodes.
When a node requires information(file) from the server, it request the server about file. The server
simply stores the files and forwards the specified file to the node which request for it. The node
then processes the request for it. The node then processes the requested file. It can access other
resources like printer from the server.
In these networks, the user nodes gain access to required hardware, software by obtaining rights
and permission, given through a centrally controlled server.
Client/server network
In client/ server network, individual computers or note share the processing and storage of data
with server. The network has arrangement of special software for nodes and server to share
processing. In this architecture, these are certain servers, dedicated for specific jobs. When a client
or node requests about any information from the server, the server processes the data and returns
only the requested information to the client.
This client/ server arrangement can be used on LAN’s or WANs. This is useful in cases where a
database can be accessed by many computers on the network. The database is stored on the
network server, along with a portion of the database management system (DBMS). The computer
working as a node stores and runs the client portion of the DBMS.
When the user with computer node requires any information in the database, he uses client
software to send the query to the server, which searches the database and returns the information
to the user.
NETWORK HARDWARE
The hardware used to connect different networks with different transmission media is naturally
different. There are Hubs, Bridges, Switches, Routers, etc. which are used at various levels in
Networking.
All these devices operate in different layers of networks as follows.
A hub has a number of input lines (nodes) and it joins all lines electrically.
Data arriving on any of the lines is sent to all other lines, in addition to the destined line.
All lines must operate at the same speed.
A hub can hold multiple line cards, each with multiple inputs.
Hubs are used in networks with twisted pair cables, to connect devices and hubs can be
joined to create larger networks.
In its earlier form, a hub was used to provide a pathway for the electrical signals to travel
along and so, it was called a Passive Hub.
Now-a-days, there are Active Hubs, which regenerate the signal before providing a path to
forward it to all connected devices.
No error checking or processing on the data is done in a Hub.
Hubs are available in many shapes and sizes, with small hubs containing 5 to 8 lines and
larger ones upto 32 lines.
Switches
Switches are connecting devices in a data link layer, of an Ethernet Network.
A switch is used to connect individual computers, via twisted pair, cables, one cable for each
computer.
A switch forwards the data only to the port that connects to the destination computer, by
learning the addresses of the computers attached to it and then by matching the address of
the destination computer with the one in the data received.
This property of the switches improves the network performance by creating a direct path
between the two computers and controlling their communication.
It reduces the number of collisions on the network which occur when two computers try to
transmit data, at exactly the same time.
Bridges
Bridges are connecting devices in a data link layer of an Ethernet Network and contain
Hardware and Software facilities, which allow devices on one network to communicate with
devices on similar network.
A bridge connects 2 or more LAN’s or it can be used for segmentation of a larger network
into 2 smaller, more efficient networks.
When data arrives at the Bridge, its software extracts the destination address from it and
transfers it to the correct location.
A Bridge connects different network types using similar protocols, topologies.
A Bridges does not provide management facility.
A Bridge manages the data traffic on both sides of the network to optimize the performance
on both sides of the network. It maintains the flow of data transmission on both sides and it
doesn’t allow unnecessary data transmission. Thus it acts as traffic police.
Remote Bridges can be used to create WAN links.
Routers
Routers are used at the Network layer and are different from switches and bridges.
Routing algorithm is a part of network layer software, which decides the output line to be
used for transmission of incoming data. Usually the data reaches its destination by taking
multiple hops in between the journey.
Routers select the best path for data transmission, based on the destination address and
origin.
Routers know the addresses of computers, bridges, other routers on the network and can
determine the busy selections on the net.
These can redirect data around those sections until they clear up.
A router can be used to connect a LAN to the Internet.
A router can route the data between any two protocols, any two topologies medium like
twisted pair, coaxial wire or fibre optic.
It contains internal tables of information called routing tables, with all known network
addresses, possible paths with the cost as well.
It contains internal tables of information called routing tables, with all known network
addresses, possible paths with the cost as well.
Routers use network addresses of packages and so can be used with a routable protocol like
TCP/IP.
OSI MODEL
The Open Systems Interconnection (OSI) model was developed by the International Organisation
for Standardization (ISO) as a model for computer protocol architecture and as a framework for
developing protocol standards in l984. It consists of a set of protocols which facilitate
communication between 2 different systems.
It is an abstract model of how the equipment and network protocols should communicate and
cooperate for effective data transmission. Note that it is not a protocol but it is technology
standard by ISO.
The OSI model is a layered framework. It divides the entire data communication into small tasks or
subtasks, known as layers. These are seven layers in the OSI stack, divided into two groups as Upper
layers and Lower layers. Let us study them.
Upper Layers
7. Application Layer: It provides access to the OSI environment for users by giving an interface
through which users can communicate and data can be transferred on the network. It also provides
distributed information services.
6. Presentation Layer: It is responsible for Encrypting, Decrypting, Compressing and Decompressing
of Data during Data Transfer. It also decides how to present data to different computers by
converting it into a particular format, supported by specific computer.
5. Session Layer: It controls communication between the computers on the network. Is also notifies
the errors, if any, in the layers above it. It also decides when to set up or to break the connection
between the computers or devices.
Lower Layers
4. Transport layer : It facilitates delivery of packets in a proper sequence, by ensuring that data is
properly delivered at the correct destination and by keeping track of all packets which don’t reach
the destination and by transmitting them again.
3. Network Layer: It transfers packets from source to destination. It also identifies ways for
transferring data from one device to other over the network on the basis of the IP addresses. It
stops overloading of packets on the network and, if required, may break the large packets into
smaller size packets.
2. Data Link Layer : It specifies the action required to maintain the network communication.It
collects the packets to form frames which are transmitted over the network using hop-to-hop
delivery. It also identifies and removes errors during transmission of packets.
l. Physical Layer : It deals with the mechanical, electrical, functional and procedural characteristics
to access the physical medium of transmission, like it can specify the layouts of cables, hubs, etc. It
defines the relation between a single device and transmission medium, by specifies the ways in
which data transfer should take place.
In this section we will learn about types of connections available for internet, its working, the
services available, like E-mails, World Wide Web, Search engines, etc. Though, everybody knows
about the Net and the Web, let us have its brief introduction.
CYBER CRIMES, SNIFFING, SPOOFING
CYBER CRIMES
Internet has become a part of every bodies life. Specially lots of communication is dependent on
mobile irrespective of age group, educational status, races. Money transaction is done through
networking and ATM. Besides Social activities are also based on internet tremendously.
Practically real life and Virtual life in cyber space are being liver in parallel through internet. Hence
Cyber crimes are affecting society speedily. These criminals have low technical skill and lead
thousand of rupees a day without leaving their home and sell drugs with low risk. Wider area is
covered with internet speed using less time and cost. In globalization era cyber crimes has buoyant
international market in e-commerce for skill, tools and finished products. Most of the crimes are
linked with credit cards and online banking.
In the course of e-governance cyber crime is cracking government or companies or organisations
website and exposing them with risk to even changes in the interrupted policies. In industrial
matters electronic scams can affect customers or suppliers eg 2G scam. The sale of private digitized
data may cause a loss of individual at monetary, emotional and social front. In case of cyber crime
victimization organizations group of people or countries suffer due to faked documents.
Cyber crime is defined as an criminal act of using computer networks cyber space and world wide
web. It also includes traditional crimes through internet. For example internet fraud, Identity theft,
credit card account theft, illegal use software such as downloading music, cyber stalking denial of
service, virus dissemination, internet relay chat crime, credit card fraud, net extortion, trafficking in
child pornography, digital piracy, money laundering, phishing and counterfeiting.
In order to control the crime information technology act 2000 was amended in 2008. Cyber crime
investigation cell Mumbai police is located since 2000 at Annex III, Cyber Crime Investigation Cell
Office of Commissioner of Police, D.N. Road,Mumbai-l and on world wide net its address is
www.cybercellmumbai.gov.in From Punjab Mr. Kunwar Vijay Pratap Singh, India.-Deputy Inspector
General of Police, Punjab State Cyber Crime Cell, Mohali had contributed in specialized areas of
Criminal Law, Constitutional Law, Cyber Law and Service Law. Hand Book on Cyber laws and
investigation also enables one to prevent of being victimized. Some law firm s like http://
cybercrimeindia.org/ set the motive to redress victims of cyber crimes such as Copy right act,
Identity theft, Hacking, Pornography, cyber attacks, Online fraud.
Besides this following are some of the examples of cyber crime:
l. A recent news 2 June 20l4- Russian Evgeniy Bogachev sought over cybercrime botnet By Dave
Dave Lee Technology reporter, BBC News:” Evgeniy Bogachev was belived to be living in Russia, the
FBI said- The US has charged a Russian man with being behind a major cybercrime operation that
affected individuals and business worldwide.
2. News about MUMBAI, 20 September 2007-Maharashtra official web site was hacked in early
hours of Tuesday.
3. A news about MMS porn case- The CEO of bazee.com (an Ebay Company) was arrested for
allegedly selling the MMS clips involving school children on its website is the most apt example in
this reference.
4. The newspaper Mid-Daily published the pictures of the Indian actor kissing her boyfriend at the
Bombay nightspot and the arrest of Krishna Kumar for illegally using internet account of Col. (Retd.)
J.S.Bajwa.
5. The news of Aug. 20l3 New Delhi A total of 78 government websites were hacked and l6,035
incidents related to spam malware infection and system break-in were reported this year so far,
Minister of State for Communication & IT Milind Deora said.
SOME ACTIVITIES/ PACKAGES LEADING TO CYBER CRIMES
Hacking :Initially hacker was used for the talented programmers. Now a days many programmers
who are unauthorized used to work unethically on internet and computer so break network code
and passwords. Hacking is defined in wiktionary unauthorized access to computer, program, data or
network resource. Hackers write or use ready made programs to attack computers. Hackers desires
to destruct system programs or data. As per Computer society of India these are categorized as
(i) White hat hackers- The white hat hackers observe ethical rules, they are familiar with internet
details of the system and decode program for the betterment of system.
(ii) Grey hat hackers- IT cross between black and white hat hackers.
(iii) Black hat hackers-The black hat hackers are familiar with internet details of the system, use
them for phishing or for online fraud or scam.
Black hat hacker are involved exclusively to commit cybercrime.
Sniffer
According to wikitionary A network sniffers monitors data flowing over computer network links. It
can be a self-contained software program or a hardware device with the appropriate software or
firmware programming. Also sometimes called “network probes” or “snoops”, sniffers examine
network traffic, making a copy of the data but without redirecting or altering it. Some sniffers work
only with TCP/IP packets, but the more sophisticated tools can work with many other protocols and
at lower levels including Ethernet frames. They are used by hackers or people curious about
network traffic.
The popularity of packet sniffing stems from the fact that it sees everything.
Typical items sniffed include:
SMTP, POP, IMAP traffic
Allows intruder to read the actual e-mail.
POP, IMAP, HTTP Basic, Telnet authentication
Reads passwords off the wire in clear-text.
SMB, NFS, FTP traffic
Reads files of the wire.
SQL database
Reads financial transactions and credit card numbers.
Not only can sniffing read information that helps break into a system, it is an intrusion by itself
because it reads the very files the intruder is interested in.
This technique can be combined with active transmission for even more effective attack.
Spoofing :
As per Wikipedia, In relation of network security, spoofing attack means one person or program
successfully masquerades as another by falsifying data and thus gains illegitimate advantage.
Types of spoofing are as follows:
TCP/IP sppofing
Referrer spoofing
Poisoning of file-sharing networks
Caller ID spoofing
E-mail address spoofing
Gps spoofing
l. TCP/IP spoofing : Many of the protocols TCP/IP suite do not provide mechanism for
authentication receiver/senders address. When the sniffing program is on a segment between two
communicating end points, the intruder can impersonate one end in order to hijack the connection.
This is often combined with a denial of service (DOS) attack against the forged address so they
don’t interface anymore.
Allows abnormal traffic to be generated, such as TCP SYN floods, overlapped fragments, illegal
fragments, and TCP fingerprinting. The best attack is serve fragmentation, which fragments the TCP
header in order to prevent firewalls from filtering by port number.
Packet sniffing tools are usually written by hackers. There are many extensions for pulling desired
data off the network. The most popular are password sniffing programs.
Use of Firewalls which take care of deep packet investigation can mitigate TCP/IP snoofing attack.
2. Referrer spoofing: Some of websites especially pornographic paid site allow access by checking
referrer.
Header of http request. If this referrer header is changed to allow user to have unauthorized access.
It is called refer spoofing.
Poisoning of files-sharing networks. Spoofing can also refer to copyright holder by placing distorted
files in files sharing network.
3. Caller ID spoofing: Public telephone networks generally provide Caller ID information i.e. the
caller’s name and number, with each call. However, some technologies (especially in Voice over IP
(VOIP) networks) allow callers to forge Caller ID information and present false names and numbers.
Gateways between networks that allow such spoofing and other public networks and numbers.
Gateways between networks that allow such spoofing and other public networks then forward that
false information. Since spoofed calls can originate from other countries, the laws in the receiver’s
country may not apply to the caller. This limit’s laws’ effectiveness against the use of spoofed Caller
ID information to further a scam.
4. E-mail address spoofing: The sender information shown in e-mails (the “From” field ) can be
spoofed easily. This technique is commonly used by spammers to hide the origin of their e-mails
and leads to problems such as misdirected bounces (i.e. e-mail spam backscatter).
E-mail address spoofing is done in quite the same way as writing a forged return address using snail
mail. As long as the letter fits the protocol, (i.e. stamp, postal code) the SMTP protocol will send the
message. It can be done using a mail server the telnet.
Spam, unsolicited electronic message. Although e-mail is the most common means of transmitting
spam blogs, newgroups, social networking sites and cellular telephones are focused on targeted.
Viewed with widespread disdain, spam nonethesless remains a popular marketing tool. Spammers
are using to promote various scams and advertise pornography. Spams also contains virus or
malicious software (malware) that can invade computer (Zombies computer) and spammer can get
remote access. These zombies can make a network which is called botnet. This bot net can be
furtively controlled by spammer used to distribute spams or cyber-crime. Filtering software are
used to stop spam.
5. GPS Spoofing : A GPS spoofing attack attempts to deceive a GPS receiver by broadcasting
counterfeit GPS signals, structured to resemble a set of normal GPS signals, or by rebroadcasting
genuine signals captured elsewhere or at a different time. One of the example is the capture of a
Lockheed RQ-l70 drone aircraft in northeastern Iran in December, 20ll.
FUNCTIONS IN EXCEL
PV:-
Purpose: Returns the Present value of an investment. The present value is the total amount that a series of
payments is worth now. For example, when you borrow money, the loan amount is the present value future
to the lender.
Syntax: PV (rate, nper, pmt, fv, type)
PMT:-
Purpose: Calculates the payments for a loan based on constant payments and a constant interest rate.
Syntax: PMT (rate, nper, pv, fv, type)
PPMT
Purpose: Returns the payments on the principal for a given period for an investment based on periodic,
constant payments and a constant interest rate.
Syntax: IPMT (rate, per, nper, pv, fv, type)
IPMT
Purpose: Returns the interest payment for a given period for an investment based on periodic, constant
payments and a constant interest rate.
Syntax: IPMT (rate, per, nper, pv, fv, type)
NPER:
Purpose: Returns the number of periods for an investment based on periodic, constant payments and a
constant interest rate.
Syntax: NPER (rate, pmt, pv, fv, type)
RATE:
Purpose: Returns the interest rate per period of an annuity. RATE can have zero or more solutions.
Syntax: RATE (nper, pmt, pv, fv, type, guess)
ROUNDDOWN:
Purpose: Rounds a number down towards zero.
Syntax : ROUNDDOWN (number, num_digits)
ROUNDUP
Purpose: Rounds a number up, away from zero.
Syntax: ROUNDUP (number, num_digits)
CEILING:
Purpose: Returns number rounded up, away from zero, to the nearest multiple of significance.
Syntax: CEILING (number, significance)
FLOOR:
Purpose: Returns number down, toward zero, to the nearest multiple of significance.
Syntax: FLOOR (number, significance)
INT:
Purpose: Rounds a number down to the nearest integer.
Syntax: INT (number)
MAX:
Purpose: Returns the largest value in a set of values.
Syntax: Max (numl, num2, num3,….) where numl, num2, num3,….. are up to 30 arguments for which you
want to find the maximum value.
MIN:
Purpose: Returns the smallest value in a set of values.
Syntax: MIN(numl, num2, num3,…..) where numl, num2, num3,…. Are up to 30 arguments for which you
want to find the minimum value.
MOD:
Purpose: Returns the remainder after number is divided by divisor. The result has the same sign as divisor.
Syntax: MOD (number, divisor)
SQRT:
Purpose: Returns the positive square root of its argument.
Syntax: SQRT (number).
ABS:
Purpose: Returns the absolute value of a number. The absolute value of a number is the number without its
sign.
Syntax: ABS (number), where number is the real number whose absolute value you want.
Example: ABS(7)=7
SUM:
Purpose: Adds all the numbers in a range of cells.
Syntax: SUM (num l,num 2, num3,…..)
AVERAGE: ,
Purpose: Returns the average (arithmetic mean) of the arguments.
Syntax: AVERAGE (numl, num2, num3,….)
COUNT:
Purpose: Returns the number of values in a range.
Syntax: COUNT (Value l, value2,…)
Module – ll (Practical)
CREATING TABLES
Manager ID : integer
Department ID : integer
Mysql> create table employees
Module ll(practicals)
Modifying Tables
Write MySQL statement for the following:
a) Add a column ‘gender’ of character type of size l column to this table.
b) Add a column ‘bonus’ decimal(7,2) to this table after the salary column with default value 2000.
Drop mbonus;
Module – ll (Practicals)
Inserting/Altering Data
a) Create a table called MY_EMPLOYEE containing the columns employee id smallint which will be the
primary key , last name varchar(25) , first name varchar(25) userid varchar(8), and salary decimal (9,2).
Mysql> create table my_employee
-) (empid smallint primary key,
-) lname varchar(25),
-) fname varchar(25),
-) userid varchar(8),
-) salary decimal(9,2));
b) Display the structure of MY_EMPLOYEE table listing the names of the columns.
Mysql> desc my_employee;
c) Add a row to the table MY_EMPLOYEE without naming the coloumns. Use your own data, but give employee id as l.
mysql> insert into my_employee values
-) (l, ‘shah’ ,’ Bobby’, ‘bobl’ ,35000);
d) Add another row to the table MY_EMPLYOEE using the columns names. Use your own data but give employee id as
2.
Mysql> insert into my_employee values
-) (2,’mehta’ , ‘jignesh’,’jig2 , 40000);
e) Add another 3 rows of data together to the table MY_EMPLOYEE. Use ypur own data but give employee id as 3,4,5.
Mysql> insert into my_employee values
-) (3,’kapur’ , ‘kiran’ , ‘kir3’ ,33000),
-) (4 ,’joshi’ , vaibhav’,’vai4’ , 43000),
-) (5, ‘shroff’,’bhikaji’,’bhi5’ ,49000);
f) Change the last name of employee id 3 to Mehta in the tableMY_EMPLOYEE.
Mysql> update my_employee
-) set lname = ‘mehta’
-) where empid =3;
g) Change the salary of all the employees to 40000 if the salary is below 40000 in the table MY_EMPLOYEE.
Mysql> update my_employee
-) set salary = 40000
-) where salary(40000;
h) Delete the row of employee id 5 in the table MY_EMPLOYEE.
Mysql> delete from my_employee
-) where empid=5;
Module – ll (Practicals)
Queries
Table EMPLOYEES contains the fields emp_id smallint not null, fname varchar(20),Iname archar(20), email varchar(25)
phoneno varchar(10), hire _date, date, jobid smallint, where emp_id is the primary key.
Write MySQL statements for the following:
a) Display the structure of this table:
mysql> desc employees;
Field Type Null Key Default Extra
emp_id smallint(6) NO PRI NULL
fname varchar(20) YES NULL
lname varchar(20) YES NULL
email varchar(25) YES NULL
phoneno varchar(10) YES NULL
hire_date date YES NULL
jobid varchar(10) YES NULL
salary decimal(8,2) YES NULL
commission decimal(6,2) YES NULL
manager_id smallint(6) YES NULL
dept_id smallint(6) YES NULL
f) To display last name and salary for all employees whose salary is in the range l5000 to 24000.
Mysql> select Iname,salary
-)where salary between 15000 and 24000;
Lname Salary
Joshi 21,000.00
Jain 19,000.00
2 rows in set (0.01 sec)
g) To display last name, job_id and hire date of employees hired between Feb 20, 1998 and May 1, 1998 in
the ascending order of hire date.
Mysql> select lname, job id, hire_date
-)from employees
-) where hire_date)’1998-02-20’ and hire_date(’1998-05-01’
-)order by hire_date;
Lname Job id hire_date
Gandhi St_clerk 1998-02-21
1 row in set (0.00 sec)
h) To display the last name and department of the employees in department l0l or l03 in the alphabetic
order of last name.
mysql> select lname, dept _id
-)from employees
-)where dept_id in (101,103)
-)order by lname;
Lname Dept_id
Joshi 101
Mehta 103
2 rows in set (0.01 sec)
i)To display the last name and salary of employees who earn from l5000 to 24000 and are in department l0l
or 103. Label the columns as Employee and monthly Salary respectively.
Mysql> select lname Employee, salary ‘Monthly Salary’
-)from employees
-)where salary between 15000 and 24000 and dept _id in (101,103);
Employee Monthly Salary
Joshi 21000.00
1 row in set (0.00 sec)
j) To display the last name and hire date of every employee who was hired in 2001.
Mysql> select lname, hire_date
-)from employees
-)where year (hire_date)=2001 or hire_date like ‘2001%’;
Lname hire_ date
Joshi 2001-10-05
Jain 2001-10-12
2 rows in set, 1 warning (0.06 sec)
k) To display the last name and job type of all employees who do not have a manager.
Mysql> select lname, jobid
-)from employees
-)where manager _id is null;
Lname Jobid
Mehta gen_mgr
1 row in set (0.00 sec)
l) Display the last name salary and commission of all employees who earn commissions in the desending
order of salary and commission.
Mysql> select lname, jobid
-)from employees
-)where commission is not null or commission !=0
-)order by salary desc, commission desc;
Lname Salary Commission
Mehta 55000.00 5500.00
Gadiwala 54000.00 5400.00
Shah 35000.00 3500.00
Mehta 25000.00 2500.00
Joshi 21000.00 2100.00
Jain 19000.00 1900.00
Gandhi 14000.00 1480.00
7 rows in set (0.05 sec)
m) Display the last names of all employees where the third letter of the name is an h.
mysql> select lname
-)from employees
-)where lname like’_h%;
Lname
Mehta
Mehta
2 rows in set (0.00 sec)
n) To display the last name of the employees who have an ‘a’ and an ‘e’ in their last name.
mysql>select lname
-)from employees
-)where lname like ‘%a%’ and lname like ‘%e%’;
Lname
Mehta
Mehta
2 rows in set (0.00 sec)
o)To display the last name, jobid and salary of the employees whose jobid is sales rep or store clerk and
whose salary is not equal to 21000, 25000 or 37000.
Mysql>select lname, jobid, salary
-)from employees
-)where jobid in (’st_clerk’ ‘sa_rep’)
-)and salary not in (21000,25000,35000);
Lname Jobid Salary
Gandhi St_clerk 14000.00
Jain Sa_rep 19000.00
2 rows in set (0.01 sec)
p) To display the last name, salary and commission of all the employees whose commission amount is below
2000.
Mysql >select lname,salary,commission
-)from employees
-)where commission (2000;
Lname Salary commission
Gandhi 14000.00 1400.00
Jain 19000.00 1900.00
2 rows in set (0.00 sec)
Manager Id and department Id are common columns in the tables employees and departments. Location Id
is the column common to the tables departments and locations.
Write queries to display the last name, department number and department name for all the employees.
Mysql>(select a.lname.a.dept id,b.deptname
-)from employees a, departments b
-)where a .deptid=b. deptid;
Lname Deptid Deptname
Joshi 101 admin
Gandhi 102 purchase
Shah 102 purchase
Mehta 102 purchase
Mehta 103 accounts
Jain 104 sales
Gadiwala 104 sales
b) Create a unique listing of all jobs that are in department l0l. Include the location of the department in the
output.
Mysql>(select distinct a.jobid,b.locationid
-)from employees a, departments b
-)where a. deptid=b.deptid and a. deptid=l0l;
Jobid Location id
ad_vp 1700
c) To display the last name, department name, location Id and city of all employees who earn a commission.
Mysql> (select a.lname,b.deptname,b.locationid,c.city
-)from employees a, departments b, locations c
-)where a.deptid=b.deptid
-)and b.locationid=c.locationid
-)and a.commission)0;
Lname deptname locationid City
Joshi Admin 1700 Mumbai
Gandhi Purchase 1800 Pune
Shah Purchase 1800 Pune
Mehta Purchase 1800 Pune
Mehta Accounts 1500 Bhopal
Jain Sales 1400 Aurangabad
Gadiwala Sales 1400 Aurangabad
7 rows in set (0.00 sec)
d) Display the last name and department name of all employees who have ‘a’ in their last name.
mysql>(select a.lname,b.deptname
-)from employees a, departments b
-)where a.deptid=b.deptid
and a.lname like’ %a%’;
Lname Deptname
Gandhi Purchase
Shah Purchase
Mehta Purchase
Mehta Accounts
Jain Sales
Gadiwala Sales
6 rows in set (0.00 sec)
e) To display last name job Id, department Id and department name of all employees who work in Mumbai’.
Mysql>(select a.lname,a.jobid,a.deptid,b.deptname
-)from employees a, departments b, locations c
-)where a.deptid=b.deptid
-)and b.locationid=c.locationid
-)and c.city=’mumbai;
Lname Jobid deptid Deptname
Joshi ad_vp 101 Admin
1 row in set (0.00 sec)
f)Display all the employees last names, department name and location Id for employees who have no
manager in the order of employee Id.
Mysql>(select a. lname, b. deptname, b. locationid
-)from employees a, departments b
-)where a. deptid=b. deptid
-)and a. manager_id is null
-)order by a.emp_id;
Lname deptname Locationid
Mehta purchase 1800
1 row in set (0.02 sec)