Create Index Associated with a Constraint

Create Index Associated with a Constraint example

  

-- create Index Associated with a Constraint
CREATE TABLE t_table (
  c1 NUMBER PRIMARY KEY 
    USING INDEX (create index t_idx on t_table (c1)),
  c2 NUMBER);
  
-- create Index Associated with a Constraint
CREATE TABLE t2_table(t1 NUMBER, t2 NUMBER);

CREATE INDEX t2_idx 
  ON t2_table (t1, t2);
  
ALTER TABLE t2_table 
  ADD CONSTRAINT t2_pk 
  PRIMARY KEY (t1) 
  USING INDEX t2_idx;   

Output:

table T_TABLE created.
table T2_TABLE created.
index T2_IDX created.
table T2_TABLE altered.

Check indexes

select INDEX_NAME, INDEX_TYPE, TABLE_NAME
from USER_INDEXES
WHERE table_name in ('T_TABLE','T2_TABLE');   

Output:

INDEX_NAME INDEX_TYPE TABLE_NAME
T_IDX NORMAL T_TABLE
T2_IDX NORMAL T2_TABLE