Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
14 views

Computer Networks and MySQL - Notes

Uploaded by

neil.malhotra63
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Computer Networks and MySQL - Notes

Uploaded by

neil.malhotra63
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Notes on Networking and MySQL - Theory

ARPANET (Advanced Research Agency Network). It was the first network that came into existence in
1969, which was used by US Department of Defence (DoD).

NSFNET (National Science Federation Network): It was more capable than ARPANET and was used only
for academic research .

INTERNET ARPANET + NSFNET + PRIVATE NETWORKS = INTERNET (1990) - Later, many privately owned
businesses with their very own private systems joined with ARPANET and NSFNET to make the Internet.

Bandwidth: It is the maximum amount of data that can be transferred per second on a link. Unit: bits
per second(bps), Mega bits per second(Mbps) or Giga bits per second(Gbps).

Data transfer rate: It is the speed at which data is transferred from one device to another. It is generally
measured in Mega bits per second(Mbps) or Mega bytes per second(MBps).

For example, if bandwidth is 100 Mbps but data rate is 50 Mbps, it means maximum 100 Mb data can be
transferred but channel is transmitting only 50 Mb data per second.

Baud: It is defined as the number of signal units per second

IP address: Internet Protocol Address. It is either a four-byte (IPv4) or a sixteen-byte (IPv6) address.
Internet Service Provider provides IP Address. It is not fixed for a computer.

MAC address: Media Access Control Address. It is a six byte hexadecimal address. NIC Card’s
Manufacturer provides the MAC Address. It is fixed for a computer.

Types of networks (PAN, LAN, MAN, WAN)-

PAN: Personal Area Network, It is mostly personal devices network equipped within a limited area. PAN
includes mobile devices, tablet, and laptop. It offers only short-range solution up to ten meters

LAN: Local Area Network. group of computer and peripheral devices which are connected in a limited
area such as school, laboratory, home, and office building.

MAN: Metropolitan Area Network. computer network across an entire city, college campus, or a small
region. It mostly covers towns and cities in a maximum 50 km range. Mostly used medium is optical
fibers, cables

WAN: Wide Area Network. computer network that which is spread across a large geographical area.
WAN network system could be a connection of a LAN which connects with other LAN’s using telephone
lines and radio waves. It is mostly limited to an enterprise or an organization.

Star Topology : Star topology is basically used for Local Area networks in which all nodes are
connected to a central point called Hub, which connects them into the communication channel. Here
communication between nodes are done through central node i.e., hub or router. The complexity of
Star topology is really simple. The cost of star topology is lower than tree topology. Star topology is used
in LAN as setup and modification is easy

Bus Topology : Bus topology is a type of network topology in which all the devices are connected to a
single cable which is called the backbone of the network. It consists of a terminator at each end of the
cable. When data reaches the end of the cable it is removed by the terminator from the data line. It is
the easiest network topology when the devices are to be connected in a linear fashion.

Tree Topology :Tree topology is a type of network topology in which the nodes are organized in the
form of a tree. In tree topology, design starts at the head top known as the root from which the
branching cable starts. The branching cable with no loops connect the root with all other nodes for
communication. Tree topology is more expensive as it is densely wired.
HTTP- Hyper Text Transmission Protocol. Connects through port 80. It is the backbone of the World
Wide Web (WWW).
FTP-File Transfer Protocol. Connects to Port 20 & 21, FTP is the underlying protocol that is used for
downloading and uploading of file

PPP-Point to Point Protocol (PPP) is a communication protocol of the data link layer that is used to
transmit multiprotocol data between two directly connected (point-to-point) computers.

SMTP- Connects to port 25, Simple Mail Transport Protocol (SMTP) is the standard TCP/IP email protocol
that Sends email over the Internet. Does not encrypt message. Emails are stored in the servers.

IMAP -Internet Messaging Access Protocol (IMAP) is a standard mail protocol that Stores messages until
users log on and download the messages. Emails get stored in the user computer.

TCP/IP- Transmission Control Protocol/ Internet Protocol. This is the underlying protocol that governs
the Internet.

POP3-Post Office Protocol (POP3) is a standard mail server that is used for receiving the incoming
emails. Does not encrypt messages

HTTPS- Hyper Text Transfer Protocol Secured. It helps to keep browsing safe by securely connecting the
browser or app with the websites visited. HTTPS relies on encryption technology—SSL or TLS—to secure
these connections.

TELNET- It is a type of protocol that enables one remote computer to connect to local computer over
the internet. It is also known as remote login.

VoIP- Voice of over Internet Protocol. It is used to make voice calls using a broadband Internet
connection instead of a regular (or analog) phone line.

GSM-Global System for Mobile Communication. It uses narrowband Time Division Multiple Access
(TDMA) for providing voice and text based services over mobile phone networks.

GPRS- General Packet Radio Service. It is a 3G technology that keeps the users online, allows to make
voice calls, and access internet on-the-go.
WLL-Wireless in local loop. It connects users to the local telephone company's network via wireless links
rather than traditional copper cables.

WWW- Word Wide Web. Also known as Web, is a collection of websites or web pages stored in web
servers.

Hyper Text Markup Language (HTML)- is the standard markup language for Web pages

Extensible Markup Language (XML)- It is a markup language similar to HTML where we can define our
own tags. This is a powerful way to store data in a format that can be stored, searched, and shared.

Domain names-A domain name is a unique, easy-to-remember address used to access websites, such as
‘google.com’, and ‘facebook.com’.

DNS- It is a directory service that provides a mapping between the name of a host on the network and
its numerical address.

URL- Uniform Resource Locator. Also known as a web address, contains the domain name of a site as
well as other information, including the transfer protocol and the path. For example
‘https://cloudflare.com/learning/flare.pdf’,

Website- It is a collection of linked web pages displaying information about an organization.

Web browser- It is a software that allows user to surf the net.

Web servers-It is the computer connected to the internet that store the websites and provides access
24/7 across the globe.

Web hosting- It is the service of uploading the website onto a web server.

1G: Voice Only - 1980s, first generation of wireless cellular technology, supports voice only calls. It is
analog technology, and the phones using it had poor battery life and voice quality, little security, and
were prone to dropped calls. The maximum speed of 1G technology is 2.4 Kbps.

2G: SMS and MMS – 1991, GSM networks, digital communication. The 2G telephone technology
introduced call and text encryption, along with data services such as SMS, picture messages, and MMS.
The maximum speed of 2G with General Packet Radio Service (GPRS) is 50 Kbps.

3G: More Data, Video Calling, and Mobile Internet – 1998. The term "mobile broadband" was first
applied to 3G cellular technology. The maximum speed of 3G is estimated to be around 2 Mbps for non-
moving devices and 384 Kbps in moving vehicles.

4G: The Current Standard - 2008. It supports mobile web access like 3G does and also gaming services,
HD mobile TV, video conferencing, 3D TV, and other features that demand high speeds. The max speed
of a 4G network when the device is moving is 100 Mbps.

5G: The Next Standard – 2021. 5G promises significantly faster data rates, higher connection density,
much lower latency, and energy savings, among other improvements. The anticipated theoretical speed
of 5G connections is up to 20 Gbps per second.
Circuit Switching- Wired connectivity. Entire path is established physically before communication takes
place. It is slower but more reliable. More expensive.

Packet Switching- Wireless connectivity. No physical path is established. Data moves from one point to
another using store and forward. It is faster and cheaper.

Repeater – It is used to regenerate the signal to avoid data loss as an amplifier does for analog signals.

Hub – A hub is basically a multiport repeater. It is used to broadcast data and has many ports for
connecting multiple computers.

Bridge – A bridge is a used to connect two LANs working on different protocol with an added
functionality of filtering content by reading the MAC addresses of source and destination

Switch – A switch is an intelligent hub with the functionality of finding out the best path for data
packets in the network. A switch can perform error checking.

Routers – It is a device that connects a LAN to a WAN. It is used to routes data packets based on their
IP addresses.

Gateway – A gateway is a passage to connect two networks together that may work upon different
networking models. They basically work as the messenger agents that take data from one system,
interpret it, and transfer it to another system. Gateways are also called protocol converters.

NIC – NIC or network interface card is a network adapter that is used to connect the computer to the
network. It is installed in the computer to establish a LAN.

Difference Between Twisted pair cable, Co-axial cable, and Optical fiber

Characteristics Twisted pair cable Co-axial cable Optical fiber cable

Affected due to
External magnetic external magnetic The external magnetic The external magnetic
field field. field is less affected. field is not affected.

Co-axial cable has


The twisted-pair cable moderately high Optical fiber cable has a
Bandwidth has low bandwidth. bandwidth. very high bandwidth.

Installation Easy installation. Fairly easy installation. Difficult to install.


Characteristics Twisted pair cable Co-axial cable Optical fiber cable

Optical fiber cable has


Twisted pair cable has Co-axial cable has higher the highest noise
Noise immunity low noise immunity. noise immunity. immunity.

Cost The cost is very low. Cost is moderate Cost is expensive.

Repeater spacing is 2- Repeater spacing is 1-10 Repeater spacing is 10-


Repeater Spacing 10 km. km. 100 km.

Difference between Radio wave, Microwave, and Infrared waves :

Sr.
No. Basis Radio wave Micro wave Infrared wave

These are omni- These are unidirectional These are unidirectional


1. Direction directional in nature. in nature. in nature.

Requires no line of Requires line of sight Requires line of sight


sight and can pass and cannot pass and cannot pass
2. Penetration through objects. through objects. through objects.

Frequency Frequency range: 3 Frequency range: 1 GHz Frequency range: 300


3. range KHz to 1GHz. to 300 GHz. GHz to 400 GHz.

Signal/data
5. loss high. medium low.

Setup and usage Cost Setup and usage Cost is


7. Usage Cost is moderate. high. Usage Cost is very less.

Distance
8. Range 3 km 50km to 1000 km 5m
Few Tips to solve the networking applications
1. Topology: Star (most appropriate) keeping the place that holds the maximum computer as the
central node.
2. Type of network
a. For buildings/wings/offices separated by distance(metres) – LAN
b. For buildings/wings/offices separated by distance(max 50 km in a city) – MAN
c. For buildings/wings/offices separated by distance(more than 100km across country) –
WAN
3. Hilly area economically – radio wave
4. Plane area economically – micro wave
5. Across country economically – satellite link
6. Irrespective of distance and landscape, most effectively, fast, reliable without any economical
restriction – optical fibre
7. In a LAN – UTP cables
8. Server to be placed in the building/wing/office with maximum computers
9. Modem as well as router to be placed in the building hosting the server.
10. Switch or hub to be placed in every building/office/wing for connecting all the computers there.
11. Repeater to be placed in the cable exceeding a distance of 100 mtrs.

MySQL
MySQL – It is an open source RDBMS. It is used at the backend to manage the data stored in the
database. There are two components of MYSQL: SQL commands and Database. SQL stands for
Structured Query Language and database is a collection of tables.

SQL is a non-procedural language that uses a predefined a set of programs called commands to retrieve
and manipulate data in the database. These commands are not case sensitive and are categorized under
4 heads:

1. DDL commands – Data Definition Language, a set of commands that are used to modify the
structure of a table. Example: create table, drop table, alter table
2. DML commands – Data Manipulation language, a set of commands that are used to modify the
contents of a table. Example: select, insert, delete and update
3. DCL commands – Data Control Language, a set of commands that are used to control the access
of the data in the database. Example: grant, revoke
4. TCL commands – Transaction Control Language, a set of commands that are used to control the
transaction issued on the database. Example: commit, rollback

Few important terminologies:


1. Database: a collection of tables
2. Relation: It is a table of data
3. Table: A collection of data stored in a format of rows and columns.
4. Attribute: A column of a table
5. Tuple: A row of a table
6. Cardinality: Total number of rows in a table
7. Degree: Total number of columns of a table
8. Candidate key: An attribute or a set of attributes that is used to uniquely identify a tuple of a
relation. All such keys are called candidate keys that are eligible to form a primary key.
9. Alternate key: Any candidate key which is not a primary key is called an alternate key.
10. Primary key: The candidate key which is selected as the programmer to uniquely identify a tuple
of a relation. It cannot be NULL and cannot have repeating values.
11. Foreign key: An attribute of a table is called as a foreign key if it is a primary key of another
table. It can have values if it exists in the primary key attribute of the other table. It can be
repeating and cannot have NULL values.
12. Referential Integrity: This talks of the integrity that is built with the help of primary-foreign key
relationship. It avoids duplication of values and get rids of any anomalies created with deletion
of tuples.
13. Constraint: It is a check created for the data validation during creating a table. Certain rules are
placed on the attributes of a table to avoid invalid data entry as per the requirement.
a. Not null – it ensures that an entry is not null or kept blank.
b. Unique – It ensures that an entry is non repeating. It can accept one NULL value.
c. Primary – it ensures that the entry is not duplicate and is not null.
d. Foreign – It ensures referential integrity.
e. Enum – It ensures that an element of the set defined is only a valid entry.
f. Check – It ensures that an entry satisfies the condition given in the check constraint.
g. Default – It ensures that if the entry is skipped the default values goes to it.

Example of a query with all the constraints


Create table student(roll in primary key, name varchar(20), age int unique, city char(10) default ‘Delhi’,
marks decimal(5,2) check(marks>=0 and <=100), grade enum (‘A’,’B’,’C’,’D’));

14. Union – This is a type of join operation that is applied to two tables, the result table has number
of rows that is the sum of the number of rows of the two tables subtracting the number of
duplicate rows in both and number of columns as the sum of the number of columns of any of
the two tables. There is a pre requirement to the union operation and that is:
1) Both tables must have same number of columns
2) The data types of the corresponding attributes of the two tables must be same.

Table: 12A_Eng Table: 12B_Eng

Roll Name Age Roll Name Age

101 Rohit 16 201 Ram 16

102 John 17 202 Shyam 17

103 Soham 18 103 Soham 18


104 Sidd 16 203 Babita 19

R1=4, C1=3 204 Rupam 17

R2=5, C2=3

Query: Select * from 12A_Eng union select * from 12B_Eng;

Roll Name Age

101 Rohit 16

102 John 17

103 Soham 18

104 Sidd 16

201 Ram 16

202 Shyam 17

203 Babita 19

204 Rupam 17

R3=8 R1+R2-no. of duplicate rows), C3=3 (C1 or C2)

15. Cartesian product: This is product operation that is applied to two tables, the result table has
number of rows that is the product of the number of rows of the two tables and number of
columns as the sum of the number of columns of two tables.

Table: A Table: B

Roll Name City Pcode Rating

101 Rohit Delhi 100058 A

102 John Kolkata 700047 B

103 Soham Pune 400501 C

R1=3, C1=2 Kolkata 700075 B

R2=4, C2=3
Query: Select * from A, B;

Roll Name City Pcode Rating

101 Rohit Delhi 100058 A

101 Rohit Delhi 700047 B

101 Rohit Delhi 400501 C

101 Rohit Delhi 700075 B

102 John Kolkata 100058 A

102 John Kolkata 700047 B

102 John Kolkata 400501 C

102 John Kolkata 700075 B

103 Soham Pune 100058 A

103 Soham Pune 700047 B

103 Soham Pune 400501 C

103 Soham Pune 700075 B

R3=12(R1*R2), C3=3(C1+C2)

Datatypes: int/ int(<size>), decimal/decimal(<total places>,<number of places after decimal point), date,
char(<number of characters>, varchar(<number of characters>)

Various commands:

1. To display all the names of databases that exists


show databases;
2. To remove the database
drop database <name>;
3. To create a database
create database <name>;
4. To enter into a database
use <database name>;
5. To display all the table names
show tables;
6. To remove a table
drop table <name>;
7. To create a table
create table <name>(<datatype> <colname1><constraint optional>, <datatype> <colname2>, …);
8. To see the structure of a table
Desc <table name>;
9. To insert a row for all attributes in a table
insert into <tablename> values (<value1>,<value2>,<value3>,…);
10. To insert a row of specific attributes in a table
insert into <tablename>(<colname1>,<colname2>,..) values (<value1>,<value2>,..);

Table: student

Roll Name Class stream Marks

1 Rohit 12 Science 89

2 Samal 11 NULL 67

3 Gaurav 12 Commerce 90

4 Anil 12 Science 75

5 Sunil 11 Arts 65

The queries formed for the following SQL operators/ clauses and functions are w.r.t. the above table.

11. select command with the use of


1) * - to display all the columns
select * from student;

2) Distinct – unique column(s)


select distinct(name) from student;

3) Where – specific rows


select * from student where class=11;

4) And, or, not – logical operators to combine conditions


select * from student where class=11 and stream=”arts”;

5) <,>,<=,>=,=,!= - comparison operators to build condition


select * from student where class>11;

6) As, is, null, formula


select roll as “serial number” from student;
select * from student where class is NULL;
select marks*3 as “total in UTs” from student;
7) Between and in
select * from student where marks between 80 and 90;
select roll from student where class in (11,10);

8) Order by
select * from student where marks > 80 order by marks desc;
select * from student order by name;

9) Like, %, _
select * from student where name like ‘__r%’;

10) Group by
select count(*), stream from student group by stream;

11) Aggregate functions: count(), max(), min(), avg() and sum()


select max(marks) from student;
select min(marks) from student;
select sum(marks) from student;
select count(*) from student;
select avg(marks) from student;

12) Adding and deleting a column


Alter table student add column address char(30);
Alter table student drop column address;

13) Changing the column datatype


Alter table student modify marks decimal(6,2);

14) Modifying a column name


Alter table student change address add char(20);

15) Adding a primary key


Alter table student add primary key(roll);

16) Removing a primary key


Alter table student drop primary key;

17) Deleting all the rows


Delete from student;

18) Deleting specific rows


Delete from student where marks<=40;

19) Updating all the rows


Update student set marks=marks+10;

20) Updating specific rows


Update student set marks=90 where roll=5;

21) Updating multiple column values


Update student set marks=97, stream=’science’ where roll>3;

22) Counting: nulls are not counted


Select count(stream) from student;

2. Creating two linked tables using primary key foreign key relationship

student teacher

Roll Name Class stream Tid Tname Age Roll Gender

1 Rohit 12 Science 101 Raj 47 2 M

2 Samal 11 Arts 102 Yogesh 52 3 M

3 Gaurav 12 Commerce 103 Mohini 53 1 F

4 Anil 12 Science 104 Naveen 41 2 M

5 Sunil 11 Arts

To create table student

create table student( roll int primary key, name varchar(20), class varchar(10), stream int);

To create table teacher linked to student

create table teacher( tid int, tname varchar(20), age int, roll int, primary key(tid), foreign key(roll)
references student(roll));

Few queries on join:

1. To display student names and their teacher names.


Select name, tname from student, teacher where student.roll=teacher.roll;
2. To count the number of students taught by male teachers only.
Select count(*) from student,teacher where student.roll=teacher.roll and gender=’M’;
MORE ON JOINS in MYSQL
A SQL Join statement is used to combine data or rows from two or more tables based on a common field
between them. There are two types: Natural Join and Inner Join (comprises of equi join and others)

1. Natural Join :
Natural Join joins two tables based on same attribute name and datatypes. The resulting table will
contain all the attributes of both the table but keep only one copy of each common column.

Example:
Consider the two tables given below:
Student Table Marks Table

SELECT * FROM Student NATURAL JOIN Marks;

2. Inner join can have equality (=) and other operators (like <,>,<>) in the join condition. Equi join only
have equality (=) operator in the join condition. The inner JOIN is used to return rows from both tables
that satisfy the given condition.

Benefits of JOIN

• JOINS allow us to combine data from more than one table into a single result set.
• JOINS have better performance compared to sub queries
• INNER JOINS only return rows that meet the given criteria.
• OUTER JOINS can also return rows where no matches have been found. The unmatched rows
are returned with the NULL keyword.
• The major JOIN types include Inner, Left Outer, Right Outer, Cross JOINS etc.
• The frequently used clause in JOIN operations is “ON”. “USING” clause requires that matching
columns be of the same name.
• JOINS can also be used in other clauses such as GROUP BY, WHERE, SUB QUERIES, AGGREGATE
FUNCTIONS etc.
Inner Join joins two table on the basis of the column which is explicitly specified in the ON clause. The
resulting table will contain all the attributes from both the tables including common column also.
Example:
Consider the above two tables and the query is given below:
SELECT *
FROM student S INNER JOIN Marks M ON S.Roll_No = M.Roll_No;
Output :

The other types are:


• LEFT JOIN
• RIGHT JOIN
• FULL JOIN

LEFT JOIN: This join returns all the rows of the table on the left side of the join and matching rows for
the table on the right side of join. The rows for which there is no matching row on right side, the
result-set will contain null. LEFT JOIN is also known as LEFT OUTER JOIN.

RIGHT JOIN: RIGHT JOIN is similar to LEFT JOIN. This join returns all the rows of the table on the right
side of the join and matching rows for the table on the left side of join. The rows for which there is no
matching row on left side, the result-set will contain null. RIGHT JOIN is also known as RIGHT OUTER
JOIN.
FULL JOIN: FULL JOIN creates the result-set by combining result of both LEFT JOIN and RIGHT JOIN.
The result-set will contain all the rows from both the tables. The rows for which there is no matching,
the result-set will contain NULL values.

CARTESIAN JOIN: The CARTESIAN JOIN is also known as CROSS JOIN. In a CARTESIAN JOIN there is a
join for each row of one table to every row of another table.
SELF JOIN: As the name signifies, in SELF JOIN a table is joined to itself. That is, each row of the table is
joined with itself and all other rows depending on some conditions. In other words we can say that it
is a join between two copies of the same table.

How to create two tables with primary key – foreign key relationship – alternate approach

mysql> create table salesman(sid int primary key, sname varchar(20),age int,city
char(10));

mysql> create table customer(cid int, cname char(10),city char(10),rating char(1


), slid int, primary key (cid), foreign key (slid) references salesman(sid));

You might also like