You are on page 1of 56

bandwidth

(1) Bandwidth is defined as a range within a band of frequencies or wavelengths.


(2) Bandwidth is also defined as the amount of data that can be transmitted in a fixed amount of time. For digital
devices, the bandwidth is usually expressed in bits per second(bps) or bytes per second. For analog devices, the
bandwidth is expressed in cycles per second, or Hertz (Hz).
The bandwidth is particularly important for I/O devices. For example, a fast disk drive can be hampered by a bus
with a low bandwidth. This is the main reason that new buses, such as AGP, have been developed for the PC.
Differentiating Between Baseband and Broadband Signaling
Two types of signaling methods are used to transmit information over network media: baseband and broadband.
Before we get any further into 802.3 standards we should clarify the difference between the two.
Baseband
Baseband transmissions typically use digital signaling over a single wire; the transmissions themselves take the form
of either electrical pulses or light. The digital signal used in baseband transmission occupies the entire bandwidth of
the network media to transmit a single data signal. Baseband communication is bidirectional, allowing computers to
both send and receive data using a single cable. However, the sending and receiving cannot occur on the same wire
at the same time.
Using baseband transmissions, it is possible to transmit multiple signals on a single cable by using a process known
as multiplexing. Baseband uses Time-Division Multiplexing (TDM), which divides a single channel into time slots.
The key thing about TDM is that it doesn't change how baseband transmission works, only the way data is placed on
the cable.
Broadband
Whereas baseband uses digital signaling, broadband uses analog signals in the form of optical or electromagnetic
waves over multiple transmission frequencies. For signals to be both sent and received, the transmission media must
be split into two channels. Alternatively, two cables can be used: one to send and one to receive transmissions.
Multiple channels are created in a broadband system by using a multiplexing technique known as FrequencyDivision Multiplexing (FDM). FDM allows broadband media to accommodate traffic going in different directions on
a single media at the same time.
Intranet:
An intranet is a private computer network that uses Internet Protocol technologies to securely share any part of an
organization's information or operational systems within that organization.
Extranet:
An extranet is a private network that uses Internet protocols, network connectivity. An extranet can be viewed as

part of a company's intranet that is extended to users outside the company, usually via the Internet.
Internet:
The Internet is a global system of interconnected computer networks that use the standard Internet Protocol Suite
(TCP/IP) to serve billions of users worldwide.
Internet
1. Internet is wide network of computers and is open for all.
2. Internet itself contains a large number of intranets.
3. The number of users who use internet is Unlimited.
4. The Visitors traffic is unlimited.
5. Internet contains different source of information and is available for all.
Intranet
1. Intranet is also a network of computers designed for a specific group of users.
2. Intranet can be accessed from Internet but with restrictions.
3. The number of users is limited.
4. The traffic allowed is also limited.
5. Intranet contains only specific group information.

Circuit Switching:
1.) In circuit switching, there are various nodes used in the network through which the signals are passed from one
system to another.
2.) In this a number of nodes are available between two devices and hence multiple paths are available to pass a
signal.
3.) This concept is mainly used in telephony systems.
4.) This is best used for transmission of audio signals and not suitable for data transmission.
5.) This type of switching is connection oriented and may be connectionless also.
6.) Due to its old version, this technique is less popular and more expensive.

Packet Switching:
1.) In packet switching, the data is sent over the network in the form of packets i.e. a large unit of data items
wrapped into a single bigger unit.
2.)In these, the packets follows the same path that is defined for them before passing into the network.
3.) It can be used for telephony, DSL services and other data transmission services.
4.) It is best used for sending data over the network and audio and video signals can also be sent over the network
in the form of packets.
5.) It is usually a connection less service.
6.) It is a new technology and economic than the circuit switching approach.
Differences between circuit switching and packet switching

Circuit switching concept is used in Telephony networks where a dedicated line is assigned to particular
connection, the connection in this case is permanent during the connection.Considerable amount of bandwidth is
wasted in this process and at a time only one way communication is possible. Whereas in case of packet switching
packet are send on different path based on the address(Virtual or IP or MAC).Packet switching is more flexible as
well as two communication of packets is possible. Packet switching is less reliable than circuit switching as in
second case connection is fixed during operation.
Database Administrator [DBA]
Definition
Centralized control of the database is exerted by a person or group of persons under the supervision of a high-level
administrator. This person or group is referred to as the database administrator (DBA). They are the users who are
most familiar with the database and are responsible for creating, modifying, and maintaining its three levels.
Database Administrator is responsible to manage the DBMSs use and ensure that the
database is functioning properly.
DBA administers the three levels of database and consultation with the overall user community, sets up the
definition of the global view of the various users and applications and is responsible the definition and
implementation of the internal level, including the storage structure and access methods to be used for the optimum
performance of the DBMS.
DBA is responsible for granting permission to the users of the database and stores the
profile of each user in the database.
Responsibilities of DBA
Deciding the information content of the database
It is the DBAs job to decide exactly what information is to be held in the database - in other
words, to identify the entities of interest to the enterprise and to identify the information to
be recorded about those entities. Having done this, the DBA must then define the content
of the database by writing the conceptual schema.
Liaising with the users
It is the business of the DBA to liaise with users, to ensure that the data they require is
available, and to write the necessary external schemas. In addition, the mapping between
any given external schema and the conceptual schema must also be specified. In practice
the external DDL will probably include the means for specifying the mapping, but the
schema and the mapping should be clearly distinguishable.
Defining authorization checks and validation procedures
Authorization checks and validation procedures may be considered as logical extensions of
the conceptual schema. The conceptual DDL will include facilities for specifying such
checks and procedures.
Defining a strategy for backup and recovery
Once an enterprise is committed to a database, it become critically dependent on the
successful operation of that system. In the event of damage to any portion of the database
caused by human error, say, or a failure in the hardware or supporting operating system
it is essential to be able to repair the data concerned with a minimum of delay and with as
little effect as possible on the rest of the system.
Monitoring performance and responsibilities to changes in requirements
The DBA is responsible for so organizing the system as to get the performance that is best
for the enterprise and for making the appropriate adjustments change. Any change to
details of storage and access must be accompanied by a corresponding change to the
definition of the mapping to storage, so that the conceptual schema may remain constant.
Static Allocation means, that the memory for your variables is automatically allocated, either on the Stack or in
other sections of your program. You do not have to reserve extra memory using them, but on the other hand, have
also no control over the lifetime of this memory. E.g: a variable in a function, is only there until the function

finishes.
void func() {
int i; /* `i` only exists during `func` */
}
Dynamic memory allocation is a bit different. You now control the exact size and the lifetime of these memory
locations. If you don't free it, you'll run into memory leaks, which may cause your application to crash, since it, at
some point cannot allocation more memory.
int* func() {
int* mem = malloc(1024);
return mem;
}
int* mem = func(); /* still accessible */
In the upper example, the allocated memory is still valid and accessible, even though the function terminated.
When you are done with the memory, you have to free it:
free(mem);
Dynamic memory allocation
Is memory allocated at runtime using calloc(), malloc() and friends. It is sometimes also referred to as
'heap' memory, although it has nothing to do with the heap data-structure ref.
int * a = malloc(sizeof(int));
Heap memory is persistent until free() is called. In other words, you control the lifetime of the variable.
Automatic memory allocation
This is what is commonly known as 'stack' memory, and is allocated when you enter a new scope (usually when a
new function is pushed on the call stack). Once you move out of the scope, the values of automatic memory
addresses are undefined, and it is an error to access them.
int a = 43;
Note that scope does not necessarily mean function. Scopes can nest within a function, and the variable will be inscope only within the block in which it was declared. Note also that where this memory is allocated is not
specified. (On a sane system it will be on the stack, or registers for optimisation)
Static memory allocation
Is allocated at compile time, and the lifetime of a variable in static memory is the lifetime of the program.
In C, static memory can be allocated using the static keyword. The scope is the compilation unit only.
Things get more interesting when the extern keyword is considered. When an extern variable is defined the
compiler allocates memory for it. When an extern variable is declared, the compiler requires that the variable be
defined elsewhere. Failure to declare/define extern variables will cause linking problems, while failure to

declare/define static variables will cause compilation problems.


in file scope, the static keyword is optional (outside of a function):
int a = 32;
But not in function scope (inside of a function):
static int a = 32;
Technically, extern and static are two separate classes of variables in C.
extern int a; /* Declaration */
int a; /* Definition */
The Class Constructor:
A class constructor is a special member function of a class that is executed whenever we create new objects of
that class.
A constructor will have exact same name as the class and it does not have any return type at all, not even void.
Constructors can be very useful for setting initial values for certain member variables.
Following example explains the concept of constructor:
#include <iostream>
using namespace std;
class Line
{
public:
void setLength( double len );
double getLength( void );
Line(); // This is the constructor

};

private:
double length;

// Member functions definitions including constructor


Line::Line(void)
{
cout << "Object is being created" << endl;
}
void Line::setLength( double len )
{
length = len;
}
double Line::getLength( void )
{
return length;
}

// Main function for the program


int main( )
{
Line line;
// set line length
line.setLength(6.0);
cout << "Length of line : " << line.getLength() <<endl;
}

return 0;

When the above code is compiled and executed, it produces the following result:
Object is being created
Length of line : 6
Parameterized Constructor:
A default constructor does not have any parameter, but if you need, a constructor can have parameters. This helps
you to assign initial value to an object at the time of its creation as shown in the following example:
#include <iostream>
using namespace std;
class Line
{
public:
void setLength( double len );
double getLength( void );
Line(double len); // This is the constructor
private:
double length;
};
// Member functions definitions including constructor
Line::Line( double len)
{
cout << "Object is being created, length = " << len << endl;
length = len;
}
void Line::setLength( double len )
{
length = len;
}
double Line::getLength( void )
{
return length;
}
// Main function for the program

int main( )
{
Line line(10.0);
// get initially set length.
cout << "Length of line : " << line.getLength() <<endl;
// set line length again
line.setLength(6.0);
cout << "Length of line : " << line.getLength() <<endl;
return 0;
}
When the above code is compiled and executed, it produces the following result:
Object is being created, length = 10
Length of line : 10
Length of line : 6
Using Initialization Lists to Initialize Fields:
In case of parameterized constructor, you can use following syntax to initialize the fields:
Line::Line( double len): length(len)
{
cout << "Object is being created, length = " << len << endl;
}
Above syntax is equal to the following syntax:
Line::Line( double len)
{
cout << "Object is being created, length = " << len << endl;
length = len;
}
If for a class C, you have multiple fields X, Y, Z, etc., to be initialized, then use can use same syntax and separate
the fields by comma as follows:
C::C( double a, double b, double c): X(a), Y(b), Z(c)
{
....
}
The Class Destructor:
A destructor is a special member function of a class that is executed whenever an object of it's class goes out of
scope or whenever the delete expression is applied to a pointer to the object of that class.
A destructor will have exact same name as the class prefixed with a tilde (~) and it can neither return a value nor
can it take any parameters. Destructor can be very useful for releasing resources before coming out of the program
like closing files, releasing memories etc.

Following example explains the concept of destructor:


#include <iostream>
using namespace std;
class Line
{
public:
void setLength( double len );
double getLength( void );
Line();
// This is the constructor declaration
~Line(); // This is the destructor: declaration
private:
double length;
};
// Member functions definitions including constructor
Line::Line(void)
{
cout << "Object is being created" << endl;
}
Line::~Line(void)
{
cout << "Object is being deleted" << endl;
}
void Line::setLength( double len )
{
length = len;
}
double Line::getLength( void )
{
return length;
}
// Main function for the program
int main( )
{
Line line;
// set line length
line.setLength(6.0);
cout << "Length of line : " << line.getLength() <<endl;
return 0;
}
When the above code is compiled and executed, it produces the following result:
Object is being created
Length of line : 6

Object is being deleted


Circuit Switching
In circuit switching network dedicated channel has to be established before the call is made between users. The
channel is reserved between the users till the connection is active. For half duplex communication, one channel is
allocated and for full duplex communication, two channels are allocated. It is mainly used for voice
communication requiring real time services without any much delay.

As shown in the figure 1, if user-A wants to use the network; it need to first ask for the request to obtain the one
and then user-A can communicate with user-C. During the connection phase if user-B tries to call/communicate
with user-D or any other user it will get busy signal from the network.
Packet Switching
In packet switching network unlike CS network, it is not required to establish the connection initially. The
connection/channel is available to use by many users. But when capacity or number of users increases then it will
lead to congestion in the network. Packet switched networks are mainly used for data and voice applications
requiring non-real time scenarios.

As shown in the figure 2, if user-A wants to send data/information to user-C and if user-B wants to send data to
user-D, it is simultaneously possible. Here information is padded with header which contains addresses of source
and destination. This header is sniffed by intermediate switching nodes to determine their route and destination.
In packet switching, station breaks long message into packets. Packets are sent one at a time to the network.
Packets are handled in two ways, viz. datagram and virtual circuit.
In datagram, each packet is treated independently. Packets can take up any practical route. Packets may arrive out
of order and may go missing.
In virtual circuit, preplanned route is established before any packets are transmitted. The handshake is established
using call request and call accept messages. Here each packet contains virtual circuit identifier(VCI) instead of the
destination address. In this type, routing decisions for each packet are not needed.
Comparison between CS vs. PS networks

As shown above in Packet switched (PS) networks quality of service (QoS) is not guaranteed while in circuit
switched (CS) networks quality is guaranteed.
PS is used for time insensitive applications such as internet/email/SMS/MMS/VOIP etc.
In CS even if user is not talking the channel cannot be used by any other users, this will waste the resource capacity
at those intervals.
The example of circuit switched network is PSTN and example of packet switched network is GPRS/EDGE.
Following table summarizes difference between circuit switching and packet switching of type datagram and
virtual circuit.

Packet Switching(Datagram
Packet Switching(Virtual Circuit type)
type)
Dedicated path
No Dedicated path
No Dedicated path
Path is established for entire
Route is established for each
Route is established for entire conversation
conversation
packet
call setup delay as well as packet transmission
Call setup delay
packet transmission delay
delay
Overload may block call setup and increases
Overload may block call setup
Overload increases packet delay
packet delay
Fixed bandwidth
Dynamic bandwidth
Dynamic bandwidth
No overhead bits after call setup overhead bits in each packet
overhead bits in each packet
Circuit Switching

Message Switching
Figure-1 depicts message switching operation. As shown in the figure, each router waits until it receives the entire
message. Once it receives the complete message it transmits the same over the next link and so on. All the routers
over the router does the same.

In a message switching Total time for Transmitting a message =


L*tPROP + L*T = L*tPROP + L*(k*P)
Where in,
L = Number of Hops
tPROP = propagation delay per hop

10

k = Number of packets which represent each message


P = time for transmitting each packet
T = time for transmitting complete message = k*P
Packet Switching
Packet switching is basically a special case of message switching type. After advancement of computer
communication and networking, packet switching came into existence.
In packet switching, the message is broken into smaller pieces. This will allow each router to start transmission as
soon as first packet of message has been arrived. This will save enormous amount of time, especially when no. of
hops between source and destination are more. Hence propagation delay is more here. The same has been depicted
in figure-2.

In packet switching, Total time for Transmitting a message =


L*tPROP + L*P + (k -1)*P
Comparison or difference between packet switching and message switching
Let us summarize comparison factors as difference between packet switching and message switching networks.

11

Message switching overhead is lower compare to packet switching. Fig-3 depicts that single datagram is
transmitted in message switching. As mentioned, message is appended with header before transmission. In packet
switching message is divided into smaller packets amd each packet is appended with header before transmission.
Overhead in message switching = header/(header+message)
Overhead in packet switching = [n*header/(n*header+message)],
Where, n = [message/packet_size]
Message switching has higher reliability and lower complexity. As in message switching, one single datagram is
either received or lost. One single network path is used for the same.
In packet switching, many packets generated by same node and belonging to the same destination may take
different paths. The packets received out of order will need to be sequenced using sequence number embedded in
the header part. May lose or corrupt a subset of the message but do not discard the entire message as in message
switching. Hence based on overall corrupt message received, what could be correct message can be interpreted.
Due to this reason, sometimes in the real time scenarios such as voice, message switching is not possible.
As explained above message switching takes more time compare to packet switching as entire message will be
stored at each of the hop points till it is completely received.

Abstract Data Types


Abstract Data Types can be used to describe how the behavior of types must be without specifying an
implementation. You define a type as a set of axioms or rules that describe what conditions must hold in every
moment. Djikstra once said that ADTs where a very useful tool to describe the behavior of queues... But well,
leaving Djikstra's known hyper-critic humor aside, I can think of at least one real application of ADT's: assertions.
Assertions allow you to specify how your type works in a formal, compilable, runnable language (as opposed to
natural language documentation). In Design by contract methodoloy they are often written as predicates that must
hold before or after the execution of a method (in general any operation on the type) in source language or some
form of meta-language. Frameworks that support assertions (such as CodeContracts for .NET) do an automatic
check that every predicate holds when it should. This way if you're own code violates one of your assertions, you
know you have a bug. So in some sense it can be seen as a form of unit testing, not by specifying test cases (which
would be the empirical testing methodology), but by specifying preconditions, post-conditions and invariants that
your type must fit (which would be the theoretical testing methodology).
Although not used in mainstream software development, as far as I know, (checking assertions can be a performance
hit) they can be used during testing.
From the purely theoretical point of view ADTs are just that, an abstraction that allows us to reason about the
behavior of types regardless of their specific implementation. If you like formalisms (like I do), nothing is better that
having a developer give you a list of theorems rather than a ambiguous babble describing what his code is supposed
to do.
On the other hand, some alternative programming paradigms (alternative as in alternative to Object-Oriented, not as
in secondary, unimportant, etc.) such as logic or functional programming are heavy based of ADTs for the types
constructions. A very interesting example is the Haskell language. It gives you a hole new picture of types,
inheritance and polymorphism

12

Database Keys
Keys are very important part of Relational database. They are used to establish and identify relation between tables.
They also ensure that each record within a table can be uniquely identified by combination of one or more fields
within a table.
Super Key
Super Key is defined as a set of attributes within a table that uniquely identifies each record within a table. Super
Key is a superset of Candidate key.
Candidate Key
Candidate keys are defined as the set of fields from which primary key can be selected. It is an attribute or set of
attribute that can act as a primary key for a table to uniquely identify each record in that table.
Primary Key
Primary key is a candidate key that is most appropriate to become main key of the table. It is a key that uniquely
identify each record in a table.

13

Composite Key
Key that consist of two or more attributes that uniquely identify an entity occurance is called Composite key. But
any attribute that makes up the Composite key is not a simple key in its own.

Secondary or Alternative key


The candidate key which are not selected for primary key are known as secondary keys or alternative keys
Non-key Attribute
Non-key attributes are attributes other than candidate key attributes in a table.
Non-prime Attribute
Non-prime Attributes are attributes other than Primary attribute.
Advantages of database
There are a number of characteristics that distinguish the database approach with the file-based approach.
Self-Describing Nature of a Database System
A Database System contains not only the database itself but also the descriptions of data structure and constraints
(meta-data). This information is used by the DBMS software or database users if needed. This separation makes a
database system totally different from the traditional file-based system in which the data definition is a part of
application programs.
Insulation between Program and Data
In the file based system, the structure of the data files is defined in the application programs so if a user wants to
change the structure of a file, all the programs that access that file might need to be changed as well. On the other
hand, in the database approach, the data structure is stored in the system catalog not in the programs. Therefore, one
change is all thats needed.
Support multiple views of data
A view is a subset of the database which is defined and dedicated for particular users of the system. Multiple users in
the system might have different views of the system. Each view might contain only the data of interest to a user or a
group of users.
Sharing of data and Multiuser system
A multiuser database system must allow multiple users access to the database at the same time. As a result, the
multiuser DBMS must have concurrency control strategies to ensure several users access to the
same data item at the same time, and to do so in a manner that the data will always be correct data integrity.
Control Data Redundancy
In the Database approach, ideally each data item is stored in only one place in the database. In some cases
redundancy still exists so as to improve system performance, but such redundancy is controlled and

14

kept to minimum.
Data Sharing
The integration of the whole data in an organization leads to the ability to produce more information from a given
amount of data.
Enforcing Integrity Constraints
DBMSs should provide capabilities to define and enforce certain constraints such as data type, data uniqueness, etc.
Restricting Unauthorised Access
Not all users of the system have the same accessing privileges. DBMSs should provide a security subsystem to
create and control the user accounts.
Data Independence
System data (Meta Data) descriptions are separated from the application programs. Changes to the data structure is
handled by the DBMS and not embedded in the program.
Transaction Processing
The DBMS must include concurrency control subsystems to ensure that several users trying to update the same data
do so in a controlled manner. The results of any updates to the database must maintain consistency and validity.
Providing multiple views of data
A view may be a subset of the database. Various users may have different views of the database itself. Users may not
need to be aware of how and where the data they refer to is stored.
Providing backup and recovery facilities
If the computer system fails in the middle of a complex update process, the recovery subsystem is responsible for
making sure that the database is restored to the stage it was in before the process started executing.
Managing information
Managing information means taking care of it so that it works for us, and is useful for the work we are doing. The
information we collect is no longer subject to accidental disorganization and becomes more easily accessible and
integrated with the rest of our work. Managing information using a database allows us to become strategic users of
the data we have.
Disadvantage of DBMS
Although there are many advantages of DBMS, the DBMS may also have some minor disadvantages. These are:

Cost of Hardware and Software

A processor with high speed of data processing and memory of large size is required to run the DBMS software. It
means that you have to up grade the hardware used for file-based system. Similarly, DBMS software is also very
costly,.

Cost of Data Conversion

When a computer file-based system is replaced with database system, the data stored into data file must be
converted to database file. It is very difficult and costly method to convert data of data file into database. You have
to hire database system designers along with application programmers. Alternatively, you have to take the services
of some software house. So a lot of money has to be paid for developing software.

Cost of Staff Training

Most database management system are often complex systems so the training for users to use the DBMS is required.
Training is required at all levels, including programming, application development, and database administration. The
organization has to be paid a lot of amount for the training of staff to run the DBMS.

Appointing Technical Staff

15

The trained technical persons such as database administrator, application programmers, data entry operations etc. are
required to handle the DBMS. You have to pay handsome salaries to these persons. Therefore, the system cost
increases.

Database Damage

In most of the organization, all data is integrated into a single database. If database is damaged due to electric failure
or database is corrupted on the storage media, the your valuable data may be lost forever.
Router vs Bridge
Basically, a router determines the fastest way possible, which is also usually the shortest way possible, in a particular
network. It has the capability to route the packets through the most effective determined route.
Routers have the ability to allow hosts that arent practically on the same logical network, to be able to communicate
with each other. Every router can receive chunks of data, which are called packets, on an interface. It will then
forward the data packets to the intended location in the most efficient manner. The directing, or routing, of packets is
based on the routing table, by allowing routers to know where a particular network is found.
Aside from being a device, a router can be software in a computer. Routers should be, at least, connected to two
networks. It is sort of a gateway to another network. Functionally, it is capable of generating traffic between
logically separated networks.
The third layer, which is the network layer of the OSI model, is where routers operate. Understanding the OSI model
is the key to figuring out differences between routers, gateways and bridges. The network layer is responsible for
moving packets from a particular port to another. It is based on addresses (L3) such as, IPv4, IPv6, and IPX, or
Appletalk, addresses.
A bridge, or network bridge, is a device that can also connect networks, but unlike a router, its operation does not
include the network layer of the OSI model. Only the one and two layers are included in a bridges operation the
physical layer and the data link layer respectively. It can only connect existing networks that you can access. It is
basically not concerned with, and is unable to distinguish networks, unlike a router. They can only be used when you
intend to connect networks of same type.
In bridging mode, the process does not bother to understand network communications protocol, such as IP
addresses. It only recognizes and considers the physical means, like the Media Access Control (MAC) address,
which is usually an Ethernet. Thus, traffic will only exist in a bridged network if the networks concerned are
logically the same.
In terms of practicality, routers are more favored, because routing is more efficient and offers easier call
management. Bridging is required for cases where you cannot subnet an IP network, and for cases where you need
to utilize non-routable protocols, like DECnet or NetBIOS.
A router, or routing, is considered more intelligent than a bridge, or bridging, because they make smarter decisions.
It only sends a packet to its intended destination, eliminating unnecessary traffic. With regards to routers, there is
improved call management, while for bridging, call management and performance is sacrificed, as packets are
automatically broadcasted to all the computers on a network.
Summary:

16

1. Routers are more intelligent than bridges.


2. Routers allow hosts that arent practically on the same logical network to be able to communicate with each other,
while bridges can only connect networks that are logically the same.
3. Routers operate at the layer 3 (network layer) of the OSI model, while bridges are only at the layer 2 (Data link
layer).
4. Routers understand and consider IP and IPX addresses, while bridges do not, and instead they recognize MAC
addresses.
5. Routing is more efficient, and has better call management, than bridging.
Do You Really Understand SQLs GROUP BY and HAVING clauses?
There are some things in SQL that we simply take for granted without thinking about them
properly.One of these things are the GROUP BY and the less popular HAVING clauses. Lets
look at a simple example. For this example, well reiterate the example database weve seen
in this previous article about the awesome LEAD(), LAG(), FIRST_VALUE(), LAST_VALUE()
functions:
1 CREATE TABLE countries (
2

code CHAR(2) NOT NULL,

year INT NOT NULL,

gdp_per_capita DECIMAL(10, 2) NOT NULL,

govt_debt DECIMAL(10, 2) NOT NULL

6 );
Before there were window functions, aggregations were made only with GROUP BY. A typical question that we
could ask our database using SQL is: What are the top 3 average government debts in percent of the GDP for those
countries whose GDP per capita was over 40000 dollars in every year in the last four years Whew. Some
(academic) business requirements.
In SQL (PostgreSQL dialect), we would write:
1 select code, avg(govt_debt)
2 from countries
3 where year > 2010
4 group by code
5 having min(gdp_per_capita) >= 40000
6 order by 2 desc

17

7 limit 3
Or, with inline comments
1 -- The average government debt
2 select code, avg(govt_debt)
3
4 -- for those countries
5 from countries
6
7 -- in the last four years
8 where year > 2010
9
10 -- yepp, for the countries
11 group by code
12
13 -- whose GDP p.c. was over 40'000 in every year
14 having min(gdp_per_capita) >= 40000
15
16 -- The top 3
17 order by 2 desc
18 limit 3
The result being:
code
avg
-----------JP
193.00
US
91.95
DE
56.00
Remember the 10 easy steps to a complete understanding of SQL:
1. FROM generates the data set
2. WHERE filters the generated data set
3. GROUP BY aggregates the filtered data set

18

4. HAVING filters the aggregated data set


5. SELECT transforms the filters aggregated data set
6. ORDER BY sorts the transformed data set
7. LIMIT .. OFFSET frames the sorted data set where
come in very different flavours.

LIMIT .. OFFSET may

The empty GROUP BY clause


A very special case of GROUP BY is the explicit or implicit empty GROUP BY clause. Heres a question that we
could ask our database: Are there any countries at all with a GDP per capita of more than 50000 dollars? And in
SQL, wed write:
1 select true answer
2 from countries
3 having max(gdp_per_capita) >= 50000
The result being
answer
-----t
You could of course have used the EXISTS clause instead (please dont use COUNT(*) in these cases):
1 select exists(
2

select 1

from countries

where gdp_per_capita >= 50000

5 );
And we would get, again:
answer
-----t
but lets focus on the plain HAVING clause.
Not everyone knows that HAVING can be used all by itself, or what it even means to have HAVING all by itself.
Already the SQL 1992 standard allowed for the use of HAVING without GROUP BY, but it wasnt until the
introduction of GROUPING SETS in SQL:1999, when the semantics of this syntax was retroactively
unambiguously defined:
7.10 <having clause>

19

<having clause> ::= HAVING <search condition>


Syntax Rules
1) Let HC be the <having clause>. Let TE be the <table expression> that immediately contains
HC. If TE does not immediately contain a <group by clause>, then GROUP BY ( ) is implicit.
Thats interesting. There is an implicit GROUP BY ( ), if we leave out the explicit GROUP BY clause. If youre
willing to delve into the SQL standard a bit more, youll find:
<group by clause> ::=
GROUP BY <grouping specification>
<grouping specification> ::=
<grouping column reference>
| <rollup list>
| <cube list>
| <grouping sets list>
| <grand total>
| <concatenated grouping>
<grouping set> ::=
<ordinary grouping set>
| <rollup list>
| <cube list>
| <grand total>
<grand total> ::= <left paren> <right paren>
So, GROUP BY ( ) is essentially grouping by a grand total, which is whats intuitively happening, if we just
look for the highest ever GDP per capita:
1 select max(gdp_per_capita)
2 from countries;
Which yields:
max
-------52409.00
The above query is also implicitly the same as this one (which isnt supported by PostgreSQL):
1 select max(gdp_per_capita)
2 from countries
3 group by ();
(but beware, this isnt always the case read this interesting article by Glenn Paulley for details)
The awesome GROUPING SETs
In this section of the article, well be leaving PostgreSQL land, entering SQL Server land, as PostgreSQL shamefully
doesnt implement any of the following (yet).

20

Now, we cannot understand the grand total (empty GROUP BY ( ) clause), without having a short look at the
SQL:1999 standard GROUPING SETS. Some of you may have heard of CUBE() or ROLLUP() grouping
functions, which are just syntactic sugar for commonly used GROUPING SETS. Lets try to answer this question in
a single query:
What are the highest GDP per capita values per year OR per country
In SQL, well write:
1 select code, year, max(gdp_per_capita)
2 from countries
3 group by grouping sets ((code), (year))
Which yields two concatenated sets of records:
code
year
max
-----------------------NULL
2009
46999.00 <- grouped by year
NULL
2010
48358.00
NULL
2011
51791.00
NULL
2012
52409.00
CA
NULL
52409.00 <- grouped by code
DE
NULL
44355.00
FR
NULL
42578.00
GB
NULL
38927.00
IT
NULL
36988.00
JP
NULL
46548.00
RU
NULL
14091.00
US
NULL
51755.00
Thats kind of nice, isnt it? Its essentially just the same thing as this query with UNION ALL
1 select code, null, max(gdp_per_capita)
2 from countries
3 group by code
4 union all
5 select null, year, max(gdp_per_capita)
6 from countries
7 group by year;
In fact, its exactly the same thing, as the latter explicitly concatenates two sets of grouped records i.e. two
GROUPING SETS. This SQL Server documentation page also explains it very nicely.
And the most powerful of them all: CUBE()

21

Now, imagine, youd like to add the grand total, and also the highest value per country AND year, producing four
different concatenated sets. To limit the results, well also filter out GDPs of less than 48000 for this example:
1

select

code, year, max(gdp_per_capita),

grouping_id(code, year) grp

from countries

where gdp_per_capita >= 48000

group by grouping sets (

(),

(code),

(year),

10

(code, year)

11 )
12 order by grp desc;
This nice-looking query will now produce all the possible grouping combinations that we can imagine, including the
grand total, in order to produce:
code
year
max
grp
--------------------------------NULL
NULL
52409.00
3 <- grand total
NULL
NULL
NULL

2012
2010
2011

52409.00
48358.00
51791.00

2 <- group by year


2
2

CA
US

NULL
NULL

52409.00
51755.00

1 <- group by code


1

US
2010
48358.00
0 <- group by code and year
CA
2012
52409.00
0
US
2012
51755.00
0
CA
2011
51791.00
0
US
2011
49855.00
0
And because this is quite a common operation in reporting and in OLAP, we can simply write the same by using the
CUBE() function:
1 select
2

code, year, max(gdp_per_capita),

22

grouping_id(code, year) grp

4 from countries
5 where gdp_per_capita >= 48000
6 group by cube(code, year)
7 order by grp desc;
The CC and BCC fields when sending email work similarly. CC stands for carbon copy, while BCC stands for
blind carbon copy. While these terms may have been immediately obvious when email was invented, theyre
antiquated today.
CC and BCC are both ways of sending copies of an email to additional people. However, you can also send copies
of an email to additional people by specifying multiple addresses in the To field.
Carbon Copying Explained
The abbreviation CC comes from carbon copy. By placing a sheet of carbon paper between two pieces of paper,
the pressure from writing on the first piece of paper will push the ink from the carbon paper down onto the second
piece of paper, producing an additional copy of the document. Like a physical carbon copy, a CC is a way of sending
additional copies of an email to other people. Some people refer to CC as courtesy copy, which better describes
what a CC actually is. CC is often used as a verb, as in I CCd him on the email.
CC vs. BCC
When you CC people on an email, the CC list is visible to all other recipients. For example, if you CC
bob@example.com and jake@example.com on an email, Bob will know that Jake also received the email, while
Jake will know that Bob also received the email.
BCC stands for blind carbon copy. Unlike with CC, no one can see the list of recipients on the BCC list. For
example, if you have bob@example.com and jake@example.com in the BCC list, Bob wont know that Jake
received the email, and Jake wont know that Bob received the email.
Someone on the BCC list can see everything else, including the CC list and the contents of the email. However, the
BCC list is secret no one can see this list. (If a person is on the BCC list, theyll see only their own email on the
BCC list.)
To vs. CC
The To and CC fields work similarly. Whether you put four email addresses in the To field or put one email address
in the To field and three in the CC field, the four people will all receive the same email. Theyll also be able to see
every other recipients email address.
When it comes to email etiquette, the To field is generally used for the main recipients of your email. The CC field is
used to send a copy to other interested parties for their information. This isnt a concrete rule, and usage of To and
CC can vary.
For example, lets say your boss wants you to email a customer in response to a complaint. Youd put the customers
email address in the To field and your bosss email address in the CC field, so your boss would receive a copy of the

23

email. (If you didnt want the customer to see your bosss email address, youd put your bosss address in the BCC
field instead.)
When to Use CC and BCC
CC is useful when:

You want someone else to receive a copy of an email, but they arent one of the primary recipients.

BCC is useful when:

You want someone else to receive an email, but you dont want the primary recipients of the email to see
youve sent this other person a copy. For example, if youre having a problem with a fellow employee, you
might send them an email about it and BCC the human resources department. HR would receive a copy for
their records, but your fellow employee wouldnt be aware of this.

You want to send a copy of an email to a large amount of people. For example, if you have a mailing list
with a large amount of people, you could include them in the BCC field. No one would be able to see
anyone elses email address if you CCd these people instead, you would be exposing their email
addresses and theyd see a long list of CCd emails in their email program. You could even put your own
email address in the To field and include every other address in the BCC field, hiding everyones email
address from each other.

Peer-to-peer (P2P) computing or networking is a distributed application architecture that partitions tasks or work
loads between peers. Peers are equally privileged, equipotent participants in the application. They are said to form a
peer-to-peer network of nodes.
Peers make a portion of their resources, such as processing power, disk storage or network bandwidth, directly
available to other network participants, without the need for central coordination by servers or stable hosts. [1] Peers
are both suppliers and consumers of resources, in contrast to the traditional client-server model in which the
consumption and supply of resources is divided. Emerging collaborative P2P systems are going beyond the era of
peers doing similar things while sharing resources, and are looking for diverse peers that can bring in unique
resources and capabilities to a virtual community thereby empowering it to engage in greater tasks beyond those that
can be accomplished by individual peers, yet that are beneficial to all the peers.
Natural join
More formally the semantics of the natural join are defined as follows:

where Fun is a predicate that is true for a relation r iff it is also true for relation s. It is usually
required that R and S must have at least one common attribute, but if this constraint is
omitted, and R and S have no common attributes, then the natural join becomes exactly the
Cartesian product.
Differences Between Structures and Classes
some of those differences to make the issue clear.

24

1. Structures are value types and the classes are reference types. Before proceeding to
the next point, let explain the difference between the two types. Imagine this is the
memory within the machine:

The value types are stored in the stack but the reference types are not. In fact, what
could be really stored in the stack for the reference types is a pointer that targets an
address at the heap level.
Then the type of structure objects are stored in the stack exactly like any value type,
say an integer, a double or a float. Meanwhile, memory locations could be reserved
for reference types in the heap. Defining the heap and stack and the difference
between them is beyond the scope of this article but nevertheless I propose this
excellent Matthew article to understand the memory mechanisms.
1.Classes are usually used for large amounts of data, whereas structs are usually
used for smaller amounts of data.
2. Classes can be inherited whereas structures not.
3. A structure couldn't be null like a class.
4. A structure couldn't have a destructor such as a class.
5. A structure can't be abstract, a class can.
6. You cannot override any methods within a structure except the following belonging to
the type object:

Equals()

GetHashCode()

GetType()

ToString()

25

And the other polymorphism technique used for structures is implementing


interfaces.

7. Declared events within a class are automatically locked and then they are thread
safe, in contrast to the structure type where events can't be locked.
8. A structure must always have the default parameter less constructor defined as
public but a class might have one, so you can't define a private parameter-less
constructor as in the following:
struct Me
{
private Me()// compile-time error
{
}
}
class Me
{
private Me()// runs Ok{
}

9. A static constructor is triggered in the case of a class but not in the case of a
structure as in the following:
struct myStructure
{
static myStructure()
{
Console.WriteLine("This is me a structure");
}
}
class myClass
{
static myClass()
{
Console.WriteLine("This is me a class");
}
}
class Program
{
static void Main(string[] args)
{
myStructure s =new myStructure();//Nothing happen
myClass c =new myClass();//Will out put This is me a class
Console.Read();
}

26

10. The strucutre can't conatain a volatile field whereas the class can
11. You can't use sizeof with classes but you can with structures
12. Fields are automatically initialized with classes to 0/false/null wheatheras strucutres
are not
13. Fields can't be directley instantiated within structures but classes allow such
operations as in the following:
struct myStructure
{
publicstring x = 2;//Not allowed
}
class myClass
{
publicstring x = 2;//Allowed
}

14. Structures and classes don't adopt the same aproach for the System.Object.Equals()
method.
Assume the following strucutre and class:
struct StructurePerson
{
publicstring FirstName;
publicstring LastName;
}
class ClassPerson
{
publicstring FirstName;
publicstring LastName;
}
Now, try this code:
class Program
{
static void Main(string[] args)
{
StructurePerson strX =new StructurePerson();
strX.LastName = "Bejaoui";
strX.FirstName = "Bechir";
StructurePerson strY =new StructurePerson();
strY.LastName = "Bejaoui";
strY.FirstName = "Bechir";

27

if (strX.Equals(strY))
{
Console.WriteLine("strX = strY");
}
else
{
Console.WriteLine("strX != strY");
}//This code displays strX = strY
ClassPerson clsX =new ClassPerson();
clsX.LastName = "Bejaoui";
clsX.FirstName = "Bechir";
ClassPerson clsY =new ClassPerson();
clsY.LastName = "Bejaoui";
clsY.FirstName = "Bechir";
if (clsX.Equals(clsY))
{
Console.WriteLine("clsX = clsY");
}
else
{
Console.WriteLine("clsX != clsY");
}//This code displays clsX != clsY
Console.Read();
}
}
In the first strucutre the two objects are value types, they are compared depending
on their values like int I = 5 and int J = 5 so I=J because they have the same value. In
the contrast, in the class case of two different and distinct references, to make clsX =
clsY you should use the following code:
ClassPerson clsX =new ClassPerson();
clsX.LastName = "Bejaoui";
clsX.FirstName = "Bechir";
ClassPerson clsY = clsX;
if (clsX.Equals(clsY))
{
Console.WriteLine("clsX = clsY");
}
else
{
Console.WriteLine("clsX != clsY");
}//This code displays clsX = clsY

28

Featured Database Articles


The HAVING and GROUP BY SQL clause
Introduction
This month's topic is one that often baffles inexperienced SQL coders. We will look at the GROUP BY clause, and
then the difference between conditions placed in the WHERE clause, and the HAVING clause. I have used
MySQL to test all of the examples, but most of them should work without any problems on other DBMS' too. We
are going to be using the following test data:
CREATE TABLE `writer` (
`poet` varchar(50) default NULL,
`anthology` varchar(40) default NULL,
`copies_in_stock` tinyint(4)
default NULL
);
INSERT INTO `writer` VALUES
('Mongane Wally Serote','Tstetlo',3),
('Mongane Wally Serote',
'No Baby Must Weep',8),
('Mongane Wally Serote',
'A Tough Tale',2),
('Douglas Livingstone',
'The Skull in the Mud',21),
('Douglas Livingstone',
'A Littoral Zone',2);
GROUP BY
Let's start with the GROUP BY clause. You can use this to group values from a column, and, if you wish, perform
calculations on that column. Let's look at a simple example:
mysql> SELECT poet,SUM(copies_in_stock) FROM writer GROUP BY poet;
+----------------------+----------------------+
| poet
| SUM(copies_in_stock) |
+----------------------+----------------------+
| Douglas Livingstone |
23 |
| Mongane Wally Serote |
13 |
+----------------------+----------------------+
Here, there are many records containing the same poet data (which is the reason why it is not normalized). The
GROUP BY function puts all of them together, allowing you to perform a calculation, such as the SUM() used to
find the total number of copies_in_stock. Here is another example:
mysql> SELECT poet,copies_in_stock FROM writer GROUP BY poet;
+----------------------+-----------------+
| poet
| copies_in_stock |
+----------------------+-----------------+
| Douglas Livingstone |
21 |
| Mongane Wally Serote |
3 |
+----------------------+-----------------+
Just what are the values in the copies_in_stock column referring to? What do they mean? Perhaps looking at the

29

full list of records may shed some light.


mysql> SELECT * FROM writer;
+----------------------+----------------------+-----------------+
| poet
| anthology
| copies_in_stock |
+----------------------+----------------------+-----------------+
| Mongane Wally Serote | Tstetlo
|
3 |
| Mongane Wally Serote | No Baby Must Weep
|
8 |
| Mongane Wally Serote | A Tough Tale
|
2 |
| Douglas Livingstone | The Skull in the Mud |
21 |
| Douglas Livingstone | A Littoral Zone
|
2 |
+----------------------+----------------------+-----------------+
The results are being grouped by the field poet, but there is no sensible way to return a value from the
copies_in_stock field. Performing a mathematical function, such as SUM() or AVG() would make sense, but what
exactly is this query asking of the database? I don't know, and neither does MySQL, so it simply returns the first
result it finds (other DBMS' may return different results). The result returned means nothing, and may not be
consistent, as it depends upon the order the DBMS happens to have placed and found the record, so there is no
point in running a query like this.
Here is another example, showing a number of common functions:
mysql> SELECT poet,
MAX(copies_in_stock) max,
MIN(copies_in_stock) min,
AVG(copies_in_stock) avg,
SUM(copies_in_stock) sum
FROM writer GROUP BY poet;
+----------------------+------+------+---------+------+
| poet
| max | min | avg
| sum |
+----------------------+------+------+---------+------+
| Douglas Livingstone |
21 |
2 | 11.5000 |
23 |
| Mongane Wally Serote |
8 |
2 | 4.3333 |
13 |
+----------------------+------+------+---------+------+
The column titles have been given aliases to make the output more readable (note that aliases more often have the
keyword AS in front of them, so this identical query may be more familiar to some):
mysql> SELECT poet,
MAX(copies_in_stock) AS max,
MIN(copies_in_stock) AS min,
AVG(copies_in_stock) AS avg,
SUM(copies_in_stock) AS sum
FROM writer GROUP BY poet;
+----------------------+------+------+---------+------+
| poet
| max | min | avg
| sum |
+----------------------+------+------+---------+------+
| Douglas Livingstone |
21 |
2 | 11.5000 |
23 |
| Mongane Wally Serote |
8 |
2 | 4.3333 |
13 |
+----------------------+------+------+---------+------+
The HAVING clause
Beginners are commonly confused about the difference between the WHERE and HAVING clauses. They are both
conditions, and look similar after all. To start with, let's have a look at these four queries:

30

mysql> SELECT poet,


MAX(copies_in_stock) AS max,
MIN(copies_in_stock) AS min,
AVG(copies_in_stock) AS avg,
SUM(copies_in_stock) AS sum
FROM writer WHERE copies_in_stock > 5 GROUP BY poet;
+----------------------+------+------+---------+------+
| poet
| max | min | avg
| sum |
+----------------------+------+------+---------+------+
| Douglas Livingstone |
21 |
21 | 21.0000 |
21 |
| Mongane Wally Serote |
8 |
8 | 8.0000 |
8 |
+----------------------+------+------+---------+------+
mysql> SELECT poet,
MAX(copies_in_stock) AS max,
MIN(copies_in_stock) AS min,
AVG(copies_in_stock) AS avg,
SUM(copies_in_stock) AS sum
FROM writer GROUP BY poet HAVING copies_in_stock > 5;
ERROR 1054 (42S22): Unknown column 'copies_in_stock' in 'having clause'
The first query only returns results where there are more than five copies in stock. Since each poet only has one
title that abides by this condition, the DBMS applies the mathematical calculations to just that one record.
Consequently, the results of the MAX(), MIN(), AVG() and SUM() calculations are all the same. The second query
attempts to do the same, but using a HAVING clause instead of a WHERE clause. It fails, because MySQL expects
a column mentioned in a HAVING clause to be present in the list of columns (see below for a discussion on
changes in this behavior with MySQL 5.0.2). This could include a function, so the following query works:
mysql> SELECT poet,
MAX(copies_in_stock) AS max,
MIN(copies_in_stock) AS min,
AVG(copies_in_stock) AS avg,
SUM(copies_in_stock) AS sum
FROM writer GROUP BY poet HAVING max > 5;
+----------------------+------+------+---------+------+
| poet
| max | min | avg
| sum |
+----------------------+------+------+---------+------+
| Douglas Livingstone |
21 |
2 | 11.5000 |
23 |
| Mongane Wally Serote |
8 |
2 | 4.3333 |
13 |
+----------------------+------+------+---------+------+
Note that the results in this case are identical, but this would not necessarily always be the case. Let us add another
record to illustrate, and then run the same two queries again:
mysql> INSERT INTO writer VALUES('Douglas Livingstone',
'Giovanni Jacopo Meditates on the High-IQ Haiku',9);
mysql> SELECT poet,
MAX(copies_in_stock) AS max,
MIN(copies_in_stock) AS min,
AVG(copies_in_stock) AS avg,
SUM(copies_in_stock) AS sum
FROM writer GROUP BY poet HAVING max > 5;
+----------------------+------+------+---------+------+
| poet
| max | min | avg
| sum |
+----------------------+------+------+---------+------+

31

| Douglas Livingstone |
21 |
2 | 10.6667 |
32 |
| Mongane Wally Serote |
8 |
2 | 4.3333 |
13 |
+----------------------+------+------+---------+------+
2 rows in set (0.00 sec)
mysql> SELECT poet,
MAX(copies_in_stock) AS max,
MIN(copies_in_stock) AS min,
AVG(copies_in_stock) AS avg,
SUM(copies_in_stock) AS sum
FROM writer WHERE copies_in_stock > 5 GROUP BY poet;
+----------------------+------+------+---------+------+
| poet
| max | min | avg
| sum |
+----------------------+------+------+---------+------+
| Douglas Livingstone |
21 |
9 | 15.0000 |
30 |
| Mongane Wally Serote |
8 |
8 | 8.0000 |
8 |
+----------------------+------+------+---------+------+
If you are unclear about why this is the case, take some time to reflect on the differences. The first query (with the
condition in the HAVING clause) applies the condition after all records have been returned. Since both of the
records have a max greater than 5, there is effectively no limiting of the results. The results are the same as they
would be without any conditions, as below:
mysql> SELECT poet,
MAX(copies_in_stock) AS max,
MIN(copies_in_stock) AS min,
AVG(copies_in_stock) AS avg,
SUM(copies_in_stock) AS sum
FROM writer GROUP BY poet;
+----------------------+------+------+---------+------+
| poet
| max | min | avg
| sum |
+----------------------+------+------+---------+------+
| Douglas Livingstone |
21 |
2 | 10.6667 |
32 |
| Mongane Wally Serote |
8 |
2 | 4.3333 |
13 |
+----------------------+------+------+---------+------+
The second query, with the condition in the WHERE clause, applies the condition before starting to calculate the
results of the functions. Therefore, for Douglas Livingstone, only two results match the condition, and the
functions then go to work on this limited set of results. Have a look at the following results, which illustrate how
the WHERE clause determines the output.
mysql> SELECT * FROM writer WHERE copies_in_stock > 5;
+----------------------+-----------------------------------------+-----------------+
| poet
| anthology
|
copies_in_stock |
+----------------------+-----------------------------------------+-----------------+
| Mongane Wally Serote | No Baby Must Weep
|
8 |
| Douglas Livingstone | The Skull in the Mud
|
21 |
| Douglas Livingstone | Giovanni Jacopo Meditates on the High-IQ |
9 |
+----------------------+-----------------------------------------+-----------------+

32

The AVG(), for example, of the two Douglas Livingstone results is 15, and the MIN() is 9, matching with the
results in the earlier query.
Here are two more examples, showing the difference between HAVING and WHERE:
mysql> SELECT poet,
MAX(copies_in_stock) AS max,
MIN(copies_in_stock) AS min,
AVG(copies_in_stock) AS avg,
SUM(copies_in_stock) AS sum
FROM writer GROUP BY poet HAVING poet > 'E';
+----------------------+------+------+--------+------+
| poet
| max | min | avg
| sum |
+----------------------+------+------+--------+------+
| Mongane Wally Serote |
8 |
2 | 4.3333 |
13 |
+----------------------+------+------+--------+------+
1 row in set (0.00 sec)
mysql> SELECT poet,
MAX(copies_in_stock) AS max,
MIN(copies_in_stock) AS min,
AVG(copies_in_stock) AS avg,
SUM(copies_in_stock) AS sum
FROM writer WHERE poet > 'E' GROUP BY poet;
+----------------------+------+------+--------+------+
| poet
| max | min | avg
| sum |
+----------------------+------+------+--------+------+
| Mongane Wally Serote |
8 |
2 | 4.3333 |
13 |
+----------------------+------+------+--------+------+
Note that they both return the same results. The poet column appears in the list of columns, so poets with a name
starting after 'E' are returned. In this case, it makes no difference to the results which way you apply the condition the same records are always excluded. However, the positioning of the condition does make a difference to the
optimization. Since the WHERE clause is carried out first, while the HAVING clause is carried out last, after all
optimizations, it usually makes more sense to place a condition in the WHERE clause, and save the HAVING
clause for conditions that are applied to fields,
Changes to the HAVING clause in MYSQL 5.0.2
Older versions of MySQL allowed the HAVING clause to refer to any field listed after the SELECT statement.
The SQL standard requires the HAVING clause to also accept fields mentioned in the GROUP BY column, even if
they are not mentioned in the SELECT expression. For example, the following query works in MYSQL 5.0.2 and
beyond, but not in earlier versions:
mysql> SELECT SUM(copies_in_stock) sum GROUP BY poet HAVING poet > 'E';
Type of Functional Dependence (FD)
A functional dependency is an association between two attributes of the same relational database table.
One of the attributes is called the determinant and the other attribute is called the determined. For each
value of the determinant there is associated one and only one value of the determined.
If A is the determinant and B is the determined then we say that A functionally determines B and
graphically represent this as A -> B. The symbols A B can also be expressed as B is functionally

33

determined by A.

Example

Since for each value of A there is associated one and only one value of B.
Example

Since for A = 3 there is associated more than one value of B.


Functional dependency can also be defined as follows:
An attribute in a relational model is said to be functionally dependent on another attribute in the table if
it can take only one value for a given value of the attribute upon which it is functionally dependent.
Example: Consider the database having following tables:

34

Here in Supplier table


Sno

Supplier number of supplier that is unique

Sname

Supplier name

City

City of the supplier

Status
- Status of the city e.g. A grade cities may have status 10, B grad cities
may have status 20 and so on.
Here, Sname is FD on Sno. Because, Sname can take only one value for the given value of Sno (e.g. S 1)
or in other words there must be one Sname for supplier number S1.
FD is represented as:
Sno Sname

35

FD is shown by which means that Sname is functionally dependent on Sno.


Similarly, city and status are also FD on Sno, because for each value of Sno there will be only one city
and status.
FD is represented as:
Sno - City
Sno - Status
S. Sno - S (Sname, City, Status)

Consider another database of shipment with following attributes:


Sno

Supplier number of the supplier

Pno

Part number supplied by supplier

Qty

Quantity supplied by supplier for a particular Part no

In this case Qty is FD on combination of Sno, Pno because each combination of Sno and Pno results only
for one Quantity.
SP (Sno, Pno) --> SP.QTY

Dependency Diagrams
A dependency diagram consists of the attribute names and all functional dependencies in a given table.
The dependency diagram of Supplier table is.

36

Here, following functional dependencies exist in supplier table


Sno

Sname

Sname
Sno

Sno

City

Sno

Status

Sname

City

Sname

Status

City

Status

The FD diagram of relation P is

Here following functional dependencies exist in Part table:

Pno - Pname
Pno - Color
Pno - Wt

37

The FD diagram of relation Shipment is


Here following functional dependencies exist in parts table
SP (Sno, Pno) - SP.QTY

Fully Functional Dependence (FFD)


Fully Functional Dependence (FFD) is defined, as Attribute Y is FFD on attribute" X, if it is FD on X and
not FD on any proper subset of X. For example, in relation Supplier, different cities may have the same
status. It may be possible that cities like Amritsar, Jalandhar may have the same status 10.
So, the City is not FD on Status.
But, the combination of Sno, Status can give only one corresponding City ,because Sno" is unique. Thus,
(Sno, Status) City
It means city is FD on composite attribute (Sno, Status) however City is not fully functional dependent
on this composite attribute, which is explained below:
(Sno, Status) City
X

Here Y is FD on X, but X has two proper subsets Sno and Status; city is FD .on one proper subset .of X
i.e. Sno
Sno City
According to 'FFD definition Y must not be FD .on any proper subset of X, but here City is FD in one

38

subset .of X i.e. Sno, so City is not FFD on (Sno, Status)


Consider another case of SP table:
Here, Qty is FD on combination of Sna, Pno.
(Sno, Pno)
X

Qty
Y

Here, X has two proper subsets Sno and Pna


Qty is not FD on Sno, because one Sna can supply mare than .one quantity.
Qty is also not FD on Pno, because .one Pna may be supplied many times by different suppliers with
different .or same quantities.
So, Qty is FFD and composite attribute of (Sno, Pno) Qty.

Other Functional Dependencies


There are same rather types of functional dependencies, which play a vital rule during the process .of
normalization of data.

Candidate Functional Dependency


A candidate functional dependency is a functional dependency that includes all attributes of the table. It
should also be noted that a well-fanned dependency diagram must have at least one candidate
functional dependency, and that there can be more than .one candidate functional dependency for a
given dependency diagram.

Primary Functional Dependency


A primary functional dependency is a candidate functional dependency that is selected to determine the
primary key. The determinant of the primary functional dependency is the primary key of the relational
database table. Each dependency diagram must have one and only on primary functional dependency. If
a relational database table has .only .one candidate functional dependency, then it automatically
becomes the primary functional dependency
Once the primary key has been determined, there will be three possible types of functional

39

dependencies:

Description
A B A key attribute functionally determines a non-key attribute.
A B A non-key attribute functionally determines a non-key attribute.
A B A non-key attribute functionally determines a key attribute.
A partial functional dependency is a functional dependency where the determinant consists of key
attributes, but not the entire primary key, and the determined consist~ of non-key attributes.
A transitive functional dependency is a functional dependency where the determinant consists of
non-key attributes and the determined also consists of non-key attributes.
A Boyce-Codd functional dependency is a functional dependency where the determinant consists
of non-key attributes and the determined consists of key attributes.
A Multi-Value Dependency (MVD) occurs when two or more independent multi valued facts about
the same attribute occur within the same table. It means that if in a relation R having A, Band C as
attributes, B and Care multi-value facts about A, which is represented as A B and A C ,then multi
value dependency exist only if B and C are independent on each other.
A Join Dependency exists if a relation R is equal to the join of the projections X Z. where X, Y, Z
projections of R.

Closure of set of dependencies


Let a relation R have some functional dependencies F specified. The closure of F (usually written as F+)
is the set of all functional dependencies that may be logically derived from F. Often F is the set of most
obvious and important functional dependencies and. F+, the closure, is the set of all the functional
dependencies including F and those that can be deduced from F. The closure is important and may, for
example, be needed in finding one or more candidate keys of the relation.
For example, the student relation has the following functional dependencies

sno Sname
cno came

40

sno address
cno instructor
Instructor office

Let these dependencies be denoted by F. The closure of F, denoted by F +, includes F and all functionaldependencies that are implied by F.

To determine F+, we need rules for deriving all functional dependencies that are implied: by F. A set of
rules that may be used to infer additional dependencies was proposed by Armstrong in 1974. These rules
(or axioms) are a complete set of rules in that all possible functional dependencies may be derived from
them. The rules are:

1. Reflexivity Rule - If X is a set of attributes and Y is a subset of X, then X Y holds.

The reflexivity rule is the simplest (almost trivial) rule. It states that each subset of X is functionally
dependent on X. In other words trivial dependence is defined as follows:
Trivial functional dependency: A trivial functional dependency is a functional dependency of an
attribute on a superset of itself.
For example: {Employee ID, Employee Address} {Employee Address} is trivial, here {Employee
Address} is a subset of {Employee ID, Employee Address}.

2. Augmentation Rule - If X Y holds and W is a set of attributes, and then WX WY holds.


The argumentation ('u rule is also quite simple. It states that if Y is determined by X then a set of
attributes W and Y together will be determined by W and X together. Note that we use the notation WX
to mean the collection of all attributes in W and X and write WX rather than the more conventional (W,
X) for convenience.
For example: Rno - Name; Class and Marks is a set of attributes and act as
W. Then {Rno, Class, Marks} -> {Name, Class, Marks}

41

3. Transitivity Rule - If X -> Y and Y -> Z hold, then X -> Z holds.


The transitivity rule is perhaps the most important one. It states that if X functionally determines Y and
Y functionally determine Z then X functionally determines Z.
For example: Rno -> City and City -> Status, then Rno -> Status should be holding true.
These rules are called Armstrong's Axioms.
Further axioms may be derived from the above although the above three axioms are sound and
complete in that they do not generate any incorrect functional dependencies (soundness) and they do
generate all possible functional dependencies that can be inferred from F (completeness). The most
important additional axioms are:

1. Union Rule - If X -> Y and X -> Z hold, then X -> YZ holds.


2. Decomposition Rule - If X YZ holds, then so do X Y and X Z.

3. Pseudotransitivity Rule - If X Y and WY Z hold then so does WX Z.


Based on the above axioms and the .functional dependencies specified for relation student, we may write
a large number of functional dependencies. Some of these are:

( sno, cno) sno (Rule 1)


(sno, cno) cno (Rule 1)
(sno, cno) (Sname, cname) (Rule 2)
cno office (Rule 3)
sno (Sname, address) (Union Rule)
Etc.
Often a very large list of dependencies can be derived from a given set F since Rule 1 itself will lead to a
large number of dependencies. Since we have seven attributes (sno, Sname, address, cno, cname,
instructor, office), there are 128 (that is, 2^7) subsets of these attributes. These 128 subsets could form
128 values of X in functional dependencies of the type X ~ Y. Of course, each value of X will then be
associated with a number of values for Y (Y being a subset of x) Leading to several thousand
dependencies. These large numbers of dependencies are not particularly helpful in achieving our aim of

42

normalizing relations.
Although we could follow the present procedure and compute the closure of F to find all the functional
dependencies, the computation requires exponential time and the list of dependencies is often very large
and therefore not very useful. There are two possible approaches that can be taken to avoid dealing with
the large number of dependencies in the closure. 'One' is to deal with one attribute or a set of attributes
at a time and find its closure (i.e. all functional dependencies relating to them). The aim of this exercise
is to find what attributes depend on a given set of attributes and therefore ought to be together. The
other approach is to find the minimal covers.

Minimal Functional Dependencies or Irreducible Set of Dependencies

In discussing the concept of equivalent FDs, it is useful to define the concept of minimal functional
dependencies or minimal cover which is useful in eliminating necessary functional dependencies so that
only the minimal numbers of dependencies need to be enforced by the system. The concept of minimal
cover of F is sometimes called irreducible Set of F.
A functional depending set S is irreducible if the set has three following properties:
Each right set of a functional dependency of S contains only one attribute.
Each left set of a functional dependency of S is irreducible. It means that reducing anyone attribute from
left set will change the content of S (S will lose some information).
Reducing any functional dependency will change the content of S.
Sets of functional dependencies with these properties are also called canonical or minimal.
Types of Relationships
Before you begin to establish relationships between tables in the database, you must know what types of
relationships can exist between a given pair of tables. Knowing how to identify them properly is an invaluable skill
for designing a database successfully.
There are three specific types of relationships that can exist between a pair of tables: one-to-one, one-to-many, and
many-to-many. The tables participate in only one type of relationship at any given time. (You'll rarely need to
change the type of relationship between a pair of tables. Only major changes in either of the table's structures could
cause you to change the relationship.)
Note
The discussion for each type of relationship begins with a generic example of the relationship. Learning how to
visualize a relationship generically enables you to understand the principle behind the relationship itself. Once you

43

understand how and why the relationship works, you'll be able to determine whether it exists between a given pair of
tables quite easily.
Each discussion also includes an example of how to diagram the relationship. I provide special instructions
pertaining to the diagramming process where appropriate and explain the symbols incorporated within the diagram
as necessary. This allows you to learn the diagramming method at a reasonable pace and keeps you from having to
memorize the entire set of diagram symbols all at once.
Figure 10.2 shows the first symbols you will use to diagram a table relationship.

One-to-One Relationships
A pair of tables bears a one-to-one relationship when a single record in the first table is related to only one record in
the second table, and a single record in the second table is related to only one record in the first table. Figure 10.3
shows a generic example of a one-to-one relationship.

As you can see, a single record in TABLE A is related to only one record in TABLE B, and a single record in
TABLE B is related to only one record in TABLE A. A one-to-one relationship usually (but not always) involves a
subset table. Figure 10.4 shows an example of a typical one-to-one relationship that you might find in a database for
an organization's human resources department. This example also illustrates a situation where neither of the tables is
a subset table.

44

Figure 10.4. A typical example of a one-to-one relationship.

Although the fields in these tables could be combined into a single table, the database designer chose to place the
fields that can be viewed by anyone in the organization in the EMPLOYEES table and the fields that can be viewed
only by authorized personnel in the COMPENSATION table. Only one record is required to store the compensation
data for a given employee, so there is a distinct one-to-one relationship between a record in the EMPLOYEES table
and a record in the COMPENSATION table.
A one-to-one relationship usually (but not always) involves a subset table. (Indeed, neither of the tables in Figure
10.4 is a subset table.) Figure 10.5 shows a generic example of how you create a relationship diagram for a one-toone relationship
dedicated server
A dedicated server is a single computer in a network reserved forserving the needs of the
network. For example, some networks require that one computer be set aside to manage
communications between all the other computers. A dedicated server could also be a
computer that manages printer resources. Note, however, that not all servers are dedicated.
In some networks, it is possible for a computer to act as a server and perform other
functions as well.
In the Web hosting business, a dedicated server is typically a rented service. The user rents the server, software and
an Internet connection from the Web host.

45

Figure 10.5. Diagramming a one-to-one relationship.

The line that appears between the tables in the diagram indicates the type of relationship, and there is a particular
line that you use for each type. Later in this chapter, you'll learn how to modify the line to show the characteristics
of the relationship as well. Figure 10.6 shows the relationship diagram for the EMPLOYEES and
COMPENSATION tables in Figure 10.4. (Note that a Data Table symbol represents each table.)
Figure 10.6. The relationship diagram for the EMPLOYEES and COMPENSATION tables.

One-to-Many Relationships
A one-to-many relationship exists between a pair of tables when a single record in the first table can be related to
one or more records in the second table, but a single record in the second table can be related to only one record in
the first table. Let's look at a generic example of this type of relationship.
Say you're working with two tables, TABLE A and TABLE B, that have a one-to-many relationship between them.
Because of the relationship, a single record in TABLE A can be related to one or more records in TABLE B. Figure
10.7 shows the relationship from the perspective of TABLE A.
Figure 10.7. A one-to-many relationship from the perspective of TABLE A.

Conversely, a single record in the TABLE B can be related to only one record in TABLE A. Figure 10.8 shows the
relationship from the perspective of TABLE B.

46

Figure 10.8. A one-to-many relationship from the perspective of TABLE B.

This is by far the most common relationship that exists between a pair of tables in a database, and it is the easiest to
identify. It is crucial from a data-integrity standpoint because it helps to eliminate duplicate data and to keep
redundant data to an absolute minimum. Figure 10.9 shows a common example of a one-to-many relationship that
you might find in a database for a video rental store.
Figure 10.9. A typical example of a one-to-many relationship.

A customer can check out any number of videos, so a single record in the CUSTOMERS table can be related to one
or more records in the CUSTOMER RENTALS table. A single video, however, is associated with only one customer
at any given time, so a single record in the CUSTOMER RENTALS table is related to only one record in the
CUSTOMERS table.
Figure 10.10 shows a generic example of how you create a relationship diagram for a one-to-many relationship.
Figure 10.10. Diagramming a one-to-many relationship.

Note that the crow's foot symbol is always located next to the table on the "many" side of the relationship. Figure
10.11 shows the relationship diagram for the CUSTOMERS and CUSTOMER RENTALS tables in Figure 10.9.

47

Figure 10.11. The relationship diagram for the CUSTOMERS and CUSTOMER RENTALS tables.

Many-to-Many Relationships
A pair of tables bears a many-to-many relationship when a single record in the first table can be related to one or
more records in the second table and a single record in the second table can be related to one or more records in the
first table.
Assume once again that you're working with TABLE A and TABLE B and that there is a many-to-many relationship
between them. Because of the relationship, a single record in TABLE A can be related to one or more records (but
not necessarily all) in TABLE B. Conversely, a single record in the TABLE B can be related to one or more records
(but not necessarily all) in TABLE A. Figure 10.12 shows the relationship from the perspective of each table.
Figure 10.12. A many-to-many relationship from the perspective of both TABLE A and TABLE
B.

This is the second most common relationship that exists between a pair of tables in a database. It can be a little more
difficult to identify than a one-to-many relationship, so you must be sure to examine the tables carefully. Figure
10.13 shows a typical example of a many-to-many relationship that you might find in a school database, which
happens to be a classic example of this type of relationship (no pun intended!).

48

Figure 10.13. A typical example of a many-to-many relationship.

A student can attend one or more classes during a school year, so a single record in the STUDENTS table can be
related to one or more records in the CLASSES table. Conversely, one or more students will attend a given class, so
a single record in the CLASSES table can be related to one or more records in the STUDENTS table.
Figure 10.14 shows a generic example of how you create a relationship diagram for a many-to-many relationship.
Figure 10.14. Diagramming a many-to-many relationship.

In this case, there is a crow's foot symbol located next to each table. Figure 10.15 shows the relationship diagram for
the STUDENTS and CLASSES tables in Figure 10.13.

49

Figure 10.15. The relationship diagram for the STUDENTS and CLASSES tables.

Problems with Many-to-Many Relationships


A many-to-many relationship has an inherent peculiarity that you must address before you can effectively use the
data from the tables involved in the relationship. The issue is this: How do you easily associate records from the first
table with records in the second table in order to establish the relationship? This is an important question because
you'll encounter problems such as these if you do not establish the relationship properly:

It will be tedious and somewhat difficult to retrieve information from one of the tables.

One of the tables will contain a large amount of redundant data.

Duplicate data will exist within both tables.

It will be difficult for you to insert, update, and delete data.

There are two common methods that novice and inexperienced developers use in a futile attempt to address this
situation. I'll demonstrate how you might apply these methods using the STUDENTS and CLASSES tables in
Figure 10.16 as examples.
Figure 10.16. Structures of the STUDENTS and CLASSES tables.

Note
As this example unfolds, keep in mind that every many-to-many relationship you encounter will exhibit these same
issues.

50

As you can see, there is no actual connection between the two tables, so you have no way of associating records in
one table with records in the other table. The first method you might use to attempt to establish a connection
involves taking a field from one table and incorporating it a given number of times within the other table. (This
approach usually appeals to people who are accustomed to working with spreadsheets.) For example, you could take
the STUDENT ID field from the STUDENTS table and incorporate it within the CLASSES table structure, creating
as many copies of the field as you need to represent the maximum number of students that could attend any class.
Figure 10.17 shows the revised version of the CLASSES table structure.
Figure 10.17. Incorporating STUDENT ID fields within the CLASSES table structure.

This structure is likely to be problematic, so you might try taking the CLASS ID field from the CLASSES table and
incorporating it within the STUDENTS table structure instead. Figure 10.18 shows the revised version of the
STUDENTS table structure.
Figure 10.18. Incorporating CLASS ID fields within the STUDENTS table structure.

51

Do these structures look (vaguely) familiar? They should. All you've done using this method is introduce a
"flattened" multivalued field into the table structure. In doing so, you've also introduced the problems associated
with a multivalued field. (If necessary, review Chapter 7.) Although you know how to resolve a multivalued field,
this is not a good or proper way to establish the relationship.
The second method you might attempt to use is simply a variation of the first method. In this case, you take one or
more fields from one table and incorporate a single instance of each field within the other table. For example, you
could take the CLASS ID, CLASS NAME, and INSTRUCTOR ID fields from the CLASSES table and incorporate
them into the STUDENTS table in order to identify the classes in which a student is currently enrolled. This may
seem to be a distinct improvement over the first method, but you'll see that there are problems that arise from such
modifications when you load the revised STUDENTS table with sample data.
Figure 10.19 clearly illustrates the problems you'll encounter using this method.

The table contains unnecessary duplicate fields. You learned all about unnecessary duplicate fields and the
problems they pose back in Chapter 7, so you know that using them here is not a good idea. Besides, it is
very likely that the CLASS NAME and INSTRUCTOR ID fields are not appropriate in the STUDENTS
tablethe CLASS ID field identifies the class sufficiently, and it is really all you need to identify the classes a
student is taking.

There is a large amount of redundant data. Even if you remove the CLASS NAME and INSTRUCTOR ID
fields from the STUDENTS table, the CLASS ID field will still produce a lot of redundant data.

It is difficult to insert a new record. If you enter a record in the STUDENTS table for a new class (instead
of entering it in the CLASSES table) without also entering student data, the fields pertaining to the student
will be nullincluding the primary key of the STUDENTS table (STUDENT ID). This will automatically
trigger a violation of the Elements of a Primary Key because the primary key cannot be null; therefore, you
cannot insert the record into the table until you can provide a proper primary key value.

It is difficult to delete a record. This is especially true if the only data about a new class has been recorded
in the particular student record you want to delete. Note the record for Diana Barlet, for example. If Diana
decides not to attend any classes this year and you delete her record, you will lose the data for the
"Introduction to Database Design" class. That might not create a serious problemunless someone neglected
to enter the data about this class into the CLASSES table as well. Once you delete Diana's record, you'll
have to re-enter all of the data for the class in the CLASSES table.

52

Figure 10.19. The revised STUDENTS table with sample data.

Fortunately, you will not have to worry about any of these problems because you're going to learn the proper way to
establish a many-to-many relationship.
Self-Referencing Relationships
This particular type of relationship does not exist between a pair of tables, which is why it isn't mentioned at the
beginning of this section. It is instead a relationship that exists between the records within a table. Ironically, you'll
still regard this throughout the design process as a table relationship.
A table bears a self-referencing relationship (also known as a recursive relationship) to itself when a given record in
the table is related to other records within the table. Similar to its dual-table counterpart, a self-referencing
relationship can be one-to-one, one-to-many, or many-to-many.
One-to-One
A self-referencing one-to-one relationship exists when a given record in the table can be related to only one other
record within the table. The MEMBERS table in Figure 10.20 is an example of a table with this type of relationship.
In this case, a given member can sponsor only one other member within the organization; the SPONSOR ID field
stores the member identification number of the member acting as a sponsor. Note that Susan McLain is Tom
Wickerath's sponsor.

Figure 10.21 shows how you diagram this type of relationship.

53

One-to-Many
A table bears a self-referencing one-to-many relationship to itself when a given record in the table can be related to
one or more other records within the table. Figure 10.22 shows an example in which a given customer can refer
other customers to the organization. The REFERRED BY field stores the customer identification number of the
customer making the referral. Note that Paul Litwin referred both Andy Baron and Mary Chipman.

Figure 10.23 shows how you diagram a self-referencing one-to-many relationship.

Many-to-Many
A self-referencing many-to-many relationship exists when a given record in the table can be related to one or more
other records within the table and one or more records can themselves be related to the given record. This may
sound somewhat confusing at first, but the example in Figure 10.24 should help clarify the matter.

54

In this case, a particular part can comprise several different component parts, and it can itself be a component of
other parts. For example, a clamp assembly (Part ID 704) is composed of a fastening bolt (Part ID 703), a bottom
clamp (Part ID 702), and a top clamp (Part ID 701). Additionally, the clamp assembly is itself a component of a seat
assembly (Part ID 707) and a frame assembly (Part ID 711). Figure 10.25 shows how you diagram this type of
relationship.

Note
Before you begin to work through the examples in the remainder of the chapter, now is a good time to remember a
principle I presented in the introduction:
Focus on the concept or technique and its intended results, not on the example used to illustrate it.
There are, without a doubt, any number of ways in which you can relate the tables in these examples (and in the case
study as well), depending on each table's role within a given database. The manner in which I use the examples here
is not important; what is important are the techniques I use to identify and establish relationships between tables.
Once you learn these techniques, you can identify and establish relationships for any pair of tables within any
context you may encounter.

Now that you've learned about the various types of table relationships, your next task is to identify the relationships
that currently exist among the tables in the database.

55

difference between routers, switches and bridges ?


A router essentially determines which way is the shortest or fastest in a network, and
routes packets accordingly. It works at layer 3 of the OSI model, moving packets from one
port to another based on L3 addresses - ie. IP addresses, IPX addresses, etc.
A switch connects one point to another in a network temporarily by turning it on and off as
necessary. It works at layer 2, with some intelligence (there are also some layer 3 switches,
that essentially have routing capabilities).
A bridge connects one point to another in a network. It works at layer 1 and 2 of the OSI
model. It only connects two segments of the network.
A bridge and a switch are very similar. In practice, a switch can be looked at as a multiport
bridge - both have the same basic functionality. They move frames between ports based on
MAC addresses. A lot of functionality can be added to switches, but the base purpose is the
same. "Layer 3" switches can be looked at as a switch with a router inside.

56

You might also like