![]() |
The SQL DROP INDEX statement removes an existing Index from a database table. SQL DROP INDEXThe SQL DROP INDEX Command is used to remove an index from the table. Indexes occupy space, which can cause extra time consumption on table modification operations. Benefits of Using DROP INDEX:
SyntaxDROP INDEX Syntax differs in different database systems. MySQL ALTER TABLE table_name DROP INDEX index_name; MS Access DROP INDEX index_name ON table_name; SQL Server DROP INDEX table_name.index_name; DB2/Oracle DROP INDEX index_name; PostgreSQL DROP INDEX index_name; SQL DROP INDEX ExampleLet’s look at some examples of how to drop an index in SQL. First, let’s create a table and add an index using the CREATE INDEX Statement. We will be using SQL database in the examples.
Output: ![]() Creating an index on two columns Now let’s look at some examples of DROP INDEX statement and understand its workings in SQL. We will learn different use cases of the SQL DROP INDEX statement with examples. We can drop the index using two ways either with IF EXISTS or with ALTER TABLE so we will first drop the index using if exists. SQL DROP INDEX with IF EXISTS ExampleRemoving an index using SQL DROP INDEX statement with IF EXISTS clause, allows the user to remove the index only if it exists in the table. Query: DROP INDEX IF EXISTS EMP ON EMPLOYEE; ![]() Dropping index OutputSince there are no indexes in the database with the supplied name, the aforementioned query simply ends execution without returning any errors. Commands Excuted Successfully; SQL DROP index with ALTER TABLE ExampleQuery: ALTER TABLE EMPLOYEE Output![]() Dropping the index Verify DROP INDEXTo verify if the DROP INDEX statement has successfully removed the index from the table, we can check the indexes on the table. If the index is not present in the list, we know it has been deleted. SyntaxThe syntax for viewing the index on a table differs for different databases, for example: SQL Server: SELECT * FROM sys.indexes WHERE object_id = (SELECT object_id FROM sys.objects WHERE name = 'YOUR_TABLE_NAME') MySQL: SHOW INDEXES FROM YOUR_TABLE_NAME; PostgreSQL: SELECT * FROM USER_INDEXES; Oracle:
Important Points About SQL DROP INDEX Statement
SQL DROP INDEX Statement – FAQsHow to create an index in SQL?
How to drop an index in SQL?
What is the need to drop an index?
|
Reffered: https://www.geeksforgeeks.org
SQL |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 13 |