DEV Community

alokz diptim!
alokz diptim!

Posted on

5 1

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:)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay