How do I find out if a SQLite index is unique? (With SQL)
Since noone's come up with a good answer, I think the best solution is this:
- If the index starts with "sqlite_autoindex", it is an auto-generated index for a single UNIQUE column
Otherwise, look for the UNIQUE keyword in the sql column in the table sqlite_master, with something like this:
SELECT * FROM sqlite_master WHERE type = 'index' AND sql LIKE '%UNIQUE%'
PRAGMA INDEX_LIST('table_name');
Returns a table with 3 columns:
seq
Unique numeric ID of indexname
Name of the indexunique
Uniqueness flag (nonzero ifUNIQUE
index.)
Edit
Since SQLite 3.16.0 you can also use table-valued pragma functions which have the advantage that you can JOIN
them to search for a specific table and column. See @mike-scotty's answer.