Example 1
Drop an unused status index and keep the table rows
Dropping the index removes only the lookup structure. The orders rows remain available, which the final SELECT confirms.
Engine-specific syntax
Setup
CREATE TABLE orders (id INT, status VARCHAR(20));
INSERT INTO
orders
VALUES
(1, 'open'),
(2, 'closed');
CREATE INDEX idx_orders_status ON orders (status);SQL
DROP INDEX idx_orders_status ON orders;
SELECT
id,
status
FROM
orders
ORDER BY
id;| id | status |
|---|---|
| 1 | open |
| 2 | closed |
Engine-specific syntax
Setup
CREATE TABLE orders (id INT, status VARCHAR(20));
INSERT INTO
orders
VALUES
(1, 'open'),
(2, 'closed');
CREATE INDEX idx_orders_status ON orders (status);SQL
DROP INDEX idx_orders_status;
SELECT
id,
status
FROM
orders
ORDER BY
id;| id | status |
|---|---|
| 1 | open |
| 2 | closed |
MySQL and MariaDB name the table in `DROP INDEX`; PostgreSQL and SQLite drop by index name.