How to create a unique index in db2?
In DB2, you can create a unique index by following these steps:
- Open the DB2 command line window or utilize the DB2 console.
- Connect to the database that you want to create an index on. Use the following command to connect to the database:
db2 connect to <database_name>
- Create a unique index by using the following command:
db2 CREATE UNIQUE INDEX <index_name> ON <table_name> (<column_name>)
In the command above, replace
For example, to create a unique index for the employee_id column in a table named employees, you can use the following command:
db2 CREATE UNIQUE INDEX emp_id_idx ON employees (employee_id)
- After executing the command, DB2 will create a unique index.
Please note that creating a unique index requires having sufficient permissions.