Hey, folks! In this article, we will be focusing on an interesting topic in the domain of database: SQL Index.
SQL serves as a standard language for the relational databases to work with ahead. It consists of various functions to enable the users to perform storage and manipulation operations effectively.
One such feature is INDEX.
So, let us begin!!
What is the SQL Index?
Index is a schema object in SQL. Moreover, the indexes actually point to the special lookup tables that enable faster retrieval of data from a particular database/table, respectively.
Let us understand the concept through the below example!
Consider a book, let’s say a Python Programming book which you want to study. Usually, each and everyone of us, first looks at the index page to understand what all topics would be covered in the course. SQL Index serves the same purpose.
Thus, an index can be considered as a pointer to a table of the database that would point to a record from the entire database.
Let us now focus on the various operations that can be performed using Index in SQL.
Creating SQL Indexes
Indexes can be created for any particular table’s column in the database. After this, the index would behave like a pointer to point the data records of the particular table.
So, let us now know the way to create an Index for a SQL Table–
Creation of Index for a SQL Table:
CREATE INDEX index-name ON TABLE columns;
Here, we point the index on the set of columns in the Create query.
Further, we can create an UNIQUE index for a set of columns by which it maintains the integrity of the data values and does not permit duplicate entries in it.
CREATE UNIQUE INDEX index-name ON TABLE columns;
Further, we can alter the index of the existing table as shown–
ALTER INDEX index-name ON Table-name REBUILD;
DROP INDEX index-name;
By this, we have come to the end of this topic. Hope this article helps you to understand the concept of Index in an easy manner!
Feel free to comment below, in case you come across any question.
Till then, Stay tuned @ SQL with JournalDev and Keep Learning!!