How to write the SQL statement to create an index in DB2?

The SQL syntax for creating an index is as follows:

CREATE INDEX index_name
ON table_name (column1, column2, ...);

In this case, index_name represents the name of the index, table_name represents the name of the table where the index will be created, and column1, column2, … indicate the specific columns on which the index will be created.

For example, to create an index on a table named users called idx_users_last_name, applied to the last_name and first_name columns, you can use the following SQL statement.

CREATE INDEX idx_users_last_name
ON users (last_name, first_name);

It is important to note that creating indexes may impact the performance of the database, so it is essential to carefully select the columns for which indexes are created in order to avoid negative effects on performance caused by too many indexes.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds