SQLite classic ...login
SQLite classic tutorial
author:php.cn  update time:2022-04-13 17:05:02

SQLite Indexed By


The "INDEXED BY index-name" clause specifies that a named index must be needed to find the value in the previous table.

If the index name index-name does not exist or cannot be used for the query, then the preparation of the SQLite statement fails.

The "NOT INDEXED" clause specifies that no index is used when accessing the preceding table (including implicit indexes created by UNIQUE and PRIMARY KEY constraints).

However, even if "NOT INDEXED" is specified, INTEGER PRIMARY KEY can still be used to find entries.

Syntax

The following is the syntax for the INDEXED BY clause, which can be used with a DELETE, UPDATE, or SELECT statement:

SELECT|DELETE| UPDATE column1, column2...
INDEXED BY (index_name)
table_name
WHERE (CONDITION);

Instance

Assuming there is table COMPANY, we will Create an index and use it for INDEXED BY operations.

sqlite> CREATE INDEX salary_index ON COMPANY(salary);
sqlite>

Now use INDEXED BY clause to select data from table COMPANY as shown below :

sqlite> SELECT * FROM COMPANY INDEXED BY salary_index WHERE salary > 5000;

php.cn