Sorting versus indexing in Database


Sorting and indexing both are important parts of the Database management system. Here is discussed Sorting versus indexing in the DBMS.

Sorting versus indexing in Database



Sorting 


Sorting means setting data properly. It can be defined as this. Sorting is arranging records from a table concerning specific fields. It makes the searching process of data easier.

We have to remember that after sorting a new table created in the database. Also the serial number of the data file record changes. If we update any record from data then sorted files don’t update. In that case, we have to apply the sorting operation again on the updated table. Sorting the records takes more time.

Your database must need security. read how to secure a database.

Types of sorting


  1.  Ascending
  2.  Descending


  1. Ascending sorting: Ascending sorting is sorting the data smaller to bigger.
  2. Descending sorting: Descending sorting is sorting the data bigger to smaller.

Example:

18,9,23,4,7,88,10 are unsorted data.

If we sort this in ascending order we get,
4, 7,9,10,18,23,88

If we sort this in descending order we get,
88,23,18,10,9,7,4

Sorting is also applicable to the words.

Example:

Master, Buy, Yellow, Net, Act, People
Ascending sort: Act, Buy, Net, People, Yellow
Descending sort: Yellow, People, Net, Buy, Act

Sorting is not applicable in Hyperlink, OLE field, Memo

Sorting tables examples


Join_Info
E_id
Name
Join_date
1011
Jordan
11.11.18
1009
Hassan
18.01.19
1017
Eliza
24.03.18
1008
Stephen
30.12.18

On this table, if we apply to sort concerning Name then we get
Ascending:

Join_Info
E_id
Name
Join_date
1017
Eliza
24.03.18
1009
Hassan
18.01.19
1011
Jordan
11.11.18
1008
Stephen
30.12.18

Descending:

Join_Info
E_id
Name
Join_date
1008
Stephen
30.12.18
1011
Jordan
11.11.18
1009
Hassan
18.01.19
1017
Eliza
24.03.18


And if we apply to sort concerning E_id then we get 

Ascending:

Join_Info
E_id
Name
Join_date
1017
Eliza
24.03.18
1011
Jordan
11.11.18
1009
Hassan
18.01.19
1008
Stephen
30.12.18

Descending:

Join_Info
E_id
Name
Join_date
1008
Stephen
30.12.18
1009
Hassan
18.01.19
1011
Jordan
11.11.18
1017
Eliza
24.03.18

We can apply to sort concerning multiple fields.

Indexing


In indexing, no change will occur in the main table. A new index file will be created. In this file, there will be no record. Only the logical order will be seen. There will be no change in the sequence number of records in the main data file. If we update or delete any records then indexed file updates automatically. It takes less time for record orders.

Example:

Join_Info
E_id
Name
Join_date
1011
Jordan
11.11.18
1009
Hassan
18.01.19
1017
Eliza
24.03.18
1008
Stephen
30.12.18

After indexing with respect to E_id in ascending order we get,

Indexing in ascending order

 Sorting versus indexing


Sorting
Indexing
Arranging records basing on specific fields.
Not changing the main table arranging the records of data table basing on the selective field.
Sequence numbers of records in main data file changes.
Sequence numbers of records in the main data file do not changes.
If any record updates, sorted files don’t update automatically.
Indexed file updates automatically if any update occurs.
More time takes for arranging the records.
Less time takes for arranging the records.
The sorting process takes more memory.
The indexing process takes less memory