Wednesday, December 23, 2009

Teradata - Secondary Index

Two challenges for this week:

1. How to create a volatile table with a secondary index
2. How to add an index to an existing table.

While there is no secondary index explicit in TD for VOLATILE tables, I found that I could simply add indices after the PRIMARY INDEX and voila:

CREATE VOLATILE TABLE FOO
(
Id INT
, Date DATE
, Product VARCHAR(20)
)
PRIMARY INDEX (Id)
INDEX (Product)
ON COMMIT PRESERVE ROWS; -- to ensure when you populate the table you can query the data.

Adding a Secondary Index (unique or non-unique) to an existing table:
create index index_name (Field) on database.table;