DEV Community

alokz diptim!
alokz diptim!

Posted on

What are SQL Indexes and how to create one? (For Beginners)

Indexes are lookup tables that when used speed up data retrival within a voluminous table.

Index SQL 1

Index SQL 2

Index SQL 3

I'll appreciate your feedback so I can improve on the sketches.

Top comments (4)

Collapse
 
giuliovn profile image
giuliovn

What happens if there is more than one result?

Collapse
 
aloksdiptim profile image
alokz diptim!

Good question Giuliovn.

Once a table is indexed based on a column field, a lookup table would be created that references the normal SQL table through the row address column.

So, for example if there are multiple instances of transaction amount, the row address in the lookup table would be pointing to the exact multiple row instance in the transaction table.

Therefore,

Select * from transaction where transactionAmount = 5000

For a multiple resultset won't be a table scan.

Collapse
 
katnel20 profile image
Katie Nelson

Your sketches are awesome and very clear.

Collapse
 
aloksdiptim profile image
alokz diptim! • Edited

Thanks Katie for the feedback:)