Back to Indexes

Ruihan Wang





Example of Creating Primary Index in Teradata RDBMS


Unique primary index for a table is created using the (UNIQUE) PRIMARY 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);

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

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);

 *** 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);

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


Non-unique primary index for a table is created using the PRIMARY INDEX clause of the CREATE TABLE statement.

 BTEQ -- Enter your DBC/SQL request or BTEQ command:
create table student (student_ID char(15), student_name char(20), Department char(10)) primary index (student_ID);

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


Once created, the primary index cannot be dropped or modified, the index must be changed by recreating the table.

 BTEQ -- Enter your DBC/SQL request or BTEQ command:
drop index (student_ID) on student;

 *** Failure 3525 The user cannot create or drop a PRIMARY index.
                Statement# 1, Info =0
 *** Total elapsed time was 1 second.