Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to drop all indexes of a sqlite table

Tags:

sqlite

I have a simple question: How to drop all indexes of a sqlite table? I have multiple indexes created with random name.

Regards,
Pentium10

like image 497
Pentium10 Avatar asked Jan 23 '10 00:01

Pentium10


People also ask

How do I drop all indexes in MySQL?

Syntax. The syntax to drop an index using the DROP INDEX statement in MySQL is: DROP INDEX index_name ON table_name; index_name.

How do you clear a table in SQLite?

The TRUNCATE TABLE statement is used to remove all records from a table. SQLite does not have an explicit TRUNCATE TABLE command like other databases. Instead, it has added a TRUNCATE optimizer to the DELETE statement. To truncate a table in SQLite, you just need to execute a DELETE statement without a WHERE clause.


1 Answers

To get all index names in a database

SELECT name FROM sqlite_master WHERE type == 'index'

For a specific table:

SELECT name FROM sqlite_master WHERE type == 'index' AND tbl_name == 'table Name'

Then in your language, iterate thought the results and drop them

FOR x IN RESULTSET
  SQL = "DROP INDEX " & X
like image 87
Robert Avatar answered Sep 20 '22 04:09

Robert