Home > Software engineering >  Verify if an index exists in a Sqlite table
Verify if an index exists in a Sqlite table

Time:09-30

I want to verify if an index exists for a SQL table. I'm trying this command (from here) :

SELECT * 
FROM sys.indexes 
WHERE name='YourIndexName' AND object_id = OBJECT_ID('Schema.YourTableName')

But I'm getting the error :

OperationalError: no such table: sys.indexes

with sqlite3 in Python.

CodePudding user response:

SELECT
   *
FROM
   sqlite_master
WHERE
   type= 'index' and tbl_name = 'your_table_name' and name = 'your_index_name';

You can use above query to verify index exist for a specific table and specific name.

  • Related