0% found this document useful (0 votes)
16 views6 pages

DBMS JOIN INDEXING (1)

Uploaded by

mishraji9333
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views6 pages

DBMS JOIN INDEXING (1)

Uploaded by

mishraji9333
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

JOIN

Join is an operation in DBMS(Database Management System) that combines the row of


two or more tables based on related columns between them. The main purpose of Join is
to retrieve the data from multiple tables .

[Join = cross product + select/condition statement]

TYPES

1) Inner join
Inner Join is a join operation in DBMS that combines two or more table based on related
columns and return only rows that have matching values among tables.

Syntax

SELECT table1.column1, table1.column2, table2.column1,....

FROM table1
INNER JOIN table2
ON table1.matching_column = table2.matching_column;
Query
SELECT EMPLOYEE.EMP_NAME, PROJECT.DEPARTMENT
FROM EMPLOYEE
INNER JOIN PROJECT
ON PROJECT.EMP_ID = EMPLOYEE.EMP_ID;

2)Left /left outer join


The SQL left join returns all the values from left table and the matching values from the right
table. If there is no matching join value, it will return NULL.
Syntax

SELECT table1.column1, table1.column2, table2.column1,....


FROM table1
LEFT JOIN table2
ON table1.matching_column = table2.matching_column;
Query

SELECT EMPLOYEE.EMP_NAME, PROJECT.DEPARTMENT


FROM EMPLOYEE
LEFT JOIN PROJECT
ON PROJECT.EMP_ID = EMPLOYEE.EMP_ID;

3)Right /right outer join


In SQL, RIGHT JOIN returns all the values from the rows of right table and the matched
values from the left table. If there is no matching in both tables, it will return NULL.

Syntax

SELECT table1.column1, table1.column2, table2.column1,....


FROM table1
RIGHT JOIN table2
ON table1.matching_column = table2.matching_column;
Query

SELECT EMPLOYEE.EMP_NAME, PROJECT.DEPARTMENT


FROM EMPLOYEE
RIGHT JOIN PROJECT
ON PROJECT.EMP_ID = EMPLOYEE.EMP_ID;

3)Full/full outer join


In SQL, FULL JOIN is the result of a combination of both left and right outer join. Join tables
have all the records from both tables. It puts NULL on the place of matches not found.
Syntax

SELECT table1.column1, table1.column2, table2.column1,....


FROM table1
FULL JOIN table2
ON table1.matching_column = table2.matching_column;
Query

SELECT EMPLOYEE.EMP_NAME, PROJECT.DEPARTMENT


FROM EMPLOYEE
FULL JOIN PROJECT
ON PROJECT.EMP_ID = EMPLOYEE.EMP_ID;
INDEXING
Indexing is a way to optimize performance of a database by minimizing the number of disk
accesses required when a query is processed. An index or database index is a data structure
which is used to quickly locate and access the data in a database table.
Indexes are created using some database columns.

 The first column is the Search key that contains a copy of the primary key or candidate key
of the table.
These values are stored in sorted order so that the corresponding data can be accessed
quickly (Note that the data may or may not be stored in sorted order).
 The second column is the Data Reference which contains a set of pointers holding the
address of the disk block where that particular key value can be found.

Attributes of Indexing

 Access Types: This refers to the type of access such as value-based search, range access,
etc.
 Access Time: It refers to the time needed to find a particular data element or set of
elements.
 Insertion Time: It refers to the time taken to find the appropriate space and insert new
data.
 Deletion Time: Time taken to find an item and delete it as well as update the index
structure.
 Space Overhead: It refers to the additional space required by the index
Indexing methods :

1)Primary indexing:

In this case, the primary key of the database table is used to create the index.
As primary keys are unique and are stored in sorted manner, the performance of searching
operation is quite efficient.
The primary index is classified into two types: Dense Index and Sparse Index.

Dense index

 The dense index contains an index record for every search key value in the data file. It
makes searching faster.
 In this, the number of records in the index table is same as the number of records in the
main table.
 It needs more space to store index record itself. The index records have the search key and a
pointer to the actual record on the disk.

Sparse Index:

 The index record appears only for a few items in the data file. Each item points to a block as
shown.
 To locate a record, we find the index record with the largest search key value less than or
equal to the search key value we are looking for.
 We start at that record pointed to by the index record, and proceed along the pointers in
the file (that is, sequentially) until we find the desired record.

2)Clustered indexing:

Clustering index is defined on an ordered data file. The data file is ordered on a non-key
field.
In some cases, the index is created on non-primary key columns which may not be unique
for each record. In such cases, in order to identify the records faster, we will group two or
more columns together to get the unique values and create index out of them. This method
is known as clustering index. Basically, records with similar characteristics are grouped
together and indexes are created for these groups.

3)Non-Clustered Indexing

A non-clustered index just tells us where the data lies, i.e. it gives us a list of virtual pointers
or references to the location where the data is actually stored. Data is not physically stored
in the order of the index. Instead, data is present in leaf nodes. For example, the contents
page of a book. Each entry gives us the page number or location of the information stored.

The actual data here (information on each page of book) is not organized but we have an
ordered reference (contents page) to where the data points actually lie.

4)Secondary Index

It is used to optimize query processing and access records in a database with some
information other than the usual search key (primary key). In these two levels of indexing
are used in order to reduce the mapping size of the first level and in general. Initially, for the
first level, a large range of numbers is selected so that the mapping size is small. Further,
each range is divided into further sub ranges. In order for quick memory access, first level is
stored in the primary memory. Actual physical location of the data is determined by the
second mapping level.

You might also like