Back to Indexes

Ruihan Wang





Example of creating and updating Secondary Index in Teradata RDBMS


Secondary index for a table is created using the (UNIQUE) INDEX clause of the CREATE TABLE statement.

 BTEQ -- Enter your DBC/SQL request or BTEQ command:
create table organic (serial_No integer, organic_name char(15), Carbon_number smallint, amount smallint) unique primary index (serial_No), unique index (organic_name);

 *** Table has been created.
 *** Total elapsed time was 1 second.

 BTEQ -- Enter your DBC/SQL request or BTEQ command:
create table order_log (log_No smallint, student_name char(15), order_date char(10), checkin_date char(10)) unique primary index (log_No), index (student_name);

 *** Table has been created.
 *** Total elapsed time was 1 second.


There can be one or more secondary indexes in the CREATE TABLE statement.

 BTEQ -- Enter your DBC/SQL request or BTEQ command:
create table inorganic (serial_No integer, inorgnic_name char(15), anion char(5), cation char(6), amount smallint) unique primary index (serial_No), index (anion), index (cation);

 *** Table has been created.
 *** Total elapsed time was 1 second.


Secondary indexes can be added to an existing table using the CREATE INDEX statement.

 BTEQ -- Enter your DBC/SQL request or BTEQ command:
create index index1 (order_date) on order_log;

 *** Index has been created.
 *** Total elapsed time was 1 second.


DROP INDEX can be used to dropping a named or unnamed secondary index.

 BTEQ -- Enter your DBC/SQL request or BTEQ command:
drop  index index1 on order_log;

 *** Index has been dropped.
 *** Total elapsed time was 1 second.

 BTEQ -- Enter your DBC/SQL request or BTEQ command:
drop index (anion), index (cation) on inorganic;

 *** Index has been dropped.
 *** Total elapsed time was 1 second.