Chapter Eng Table Joins and Indexes in SQL
Chapter Eng Table Joins and Indexes in SQL
By-
Neha
Tyagi
PGT CS
KV 5 Jaipur II
Shift Jaipur
Neha Tyagi, PGT Region
CS II Shift Jaipur
Introducti
• Sometimes on
we need an information
which is receiving data from multiple
tables.
• If the tables have some common field
then it become easier to join these
tables and can retrieve the data.
• In this chapter, we will learn joining of
tables and the process of information
retrieval.
• In this chapter we will also learn
indexes of SQL which facilitates
Neha Tyagi, KV 5 Jaipur II Shift
JOINS
• Join is a query which combine rows of two or
more tables.
• In a join-query, we need to provide a list of
tables in FROM Clause.
• The process of combining multiple tables in
order to retrieve data is called joining. For
ex-
In above given example there are two tables namely emp1 and dept.
In emp1 table, primary key is empcode and in table dept foreign key is
empcode which is referring empcode of emp1 table.
Now we will
see that how
join works.
Data from
each column
with the
combination
of each
record has
show on
execution of
query.
Neha Tyagi, KV 5 Jaipur II Shift
Condition is
Join
query
To get the details about the departments and their in-
charges, query will be-
Right-
• JOIN
When we use RIGHT-JOIN, it returns all rows from second table
whether it has matching rows in first table or not.
• It shows NULL in columns for the unmatched rows of second
table.
Example:
mysql>Create index Player_idx on Players (name(5));
OR
Create Unique index Player_idx on Players
(Teamno);
Neha Tyagi, KV 5 Jaipur II Shift
Indexes in
• To show theDatabase
Indexes, use the following
command –
mysql> SHOW INDEXES FROM
<TableName>; Example :
mysql> SHOW INDEXES FROM Players;
• To delete the Indexe, use the
following command
mysql> DROP INDEX <IndexName> ON
<Tablename>; Example:
mysql> Drop Index Player_idx ON Players;
• Disadvantages :
• With Indexes, the performance of insert, update and delete
decreases. As every time insert/update/delete operation
happens, the index is to be updated accordingly.
• Index consumes storage space and this increases with the
number of
fields used and the length of the table.
Neha Tyagi, KV 5 Jaipur II Shift
Thank
you
Please follow us on our
blog
www.pythontrends.wordpress.com