SQL > ALTER TABLE > Drop Index Syntax

Sometimes we may decide that a particular index is no longer needed for a table. In those cases, that index should be removed to free up storage. To drop an index in SQL, we specify that we want to change the table structure via the ALTER TABLE command, followed by the DROP INDEX command.

The SQL syntax to drop an index from a table is,

ALTER TABLE "table_name"
DROP INDEX "index_name";

Let's look at the example. Assuming our starting point is the Customer table created in the CREATE TABLE section:

Table Customer

 Column Name  Data Type 
 First_Name  char(50) 
 Last_Name  char(50) 
 Address  char(50) 
 City  char(50) 
 Country  char(25) 
 Birth_Date  datetime 

Assume we want to drop the index created in the ALTER TABLE ADD INDEX section. To do this, we type in the following:

ALTER TABLE Customer DROP INDEX IDX_COUNTRY;

Please note that using ALTER TABLE to drop an index in supported in MySQL but not in Oracle or SQL Server.

Next: SQL ADD CONSTRAINT

This page was last updated on October 11, 2024.




Copyright © 2024   1keydata.com   All Rights Reserved     Privacy Policy     About   Contact