How to create and utilize indexes in DB2?
In DB2, you can create and use indexes using the following SQL statement.
- Create an index.
CREATE INDEX index_name
ON table_name (column1, column2, ...);
This will create a new index on the specified table, allowing you to designate one or more columns as the indexed fields.
- Remove index.
DROP INDEX index_name;
This will remove the specified index from the database.
- Utilize an index:
SELECT column1, column2
FROM table_name
WHERE indexed_column = value;
Using indexes in a query can speed up data retrieval. Filtering with indexed fields in the WHERE clause ensures that the database engine uses the indexes to locate the data.