The primary index of a table should not be confused with the table’s primary key. A table can define a primary key that is the same or different from the primary index. They are mutually exclusive. In fact, a table need not have a primary key at all, but it must always have a primary index. All tables must have a primary index. If not specified explicitly when the table is created, Teradata uses the first column of the table definition as the primary index by default. The primary index can be comprised of one or more columns and does not need to be absolutely unique, although more uniqueness is always better. Let’s take the following CREATE table example:
CREATE TABLE salary
(
emp_id INTEGER,
first_name VARCHAR(30),
last_name VARCHAR(30),
amount INTEGER
)
PRIMARY INDEX (emp_id) ;
As you see, in the example above, the table does not specify a primary key, which is perfectly fine. If the values present in the emp_id column are unique in nature, then this column can be considered as a candidate for the Primary Key. While primary key can be declared either implicitly, or explicitly as follows:
CREATE TABLE salary
(
emp_id INTEGER,
first_name VARCHAR(30),
last_name VARCHAR(30),
amount INTEGER,
PRIMARY KEY(emp_id)
)
PRIMARY INDEX (emp_id) ;
In either case (having a primary key and without a primary key), the primary index is used internally within Teradata to distribute the rows of the table, while the primary key is used to uniquely identify each row within the table in order to support application requirements. But having both definitely improves faster retrieval of query results.
Popularity: 17% [?]
Our Random Articles
- How To Choose A Good Online Traffic School
- New Year Wishes 2010
- New Year Wishes
- How to use EXTRACT function with date and time columns
- How to Post on a Separate/New Page in WordPress
More Links




1 Comment
what is main role of primary key in primaryindex of teradata
Popular Articles