Teradata: how can I get the primary key and the definition of the foreign key of the table?

There are already tables, but I don’t know how they add up. Now I want to get the definition of the primary key and foreign key of the tables. How can i do this?

+4
source share
1 answer

There are several ways to get the PK / FK information in Teradata, but it may fail if PK / FK is not defined for the table. And there is a high probability (especially for FK) that they are not defined in the data warehouse. In this case, you need to get external documentation on your datamodel.

dbc.IndicesV contains all indexes, but there is one row per column per index, for example. 4 PK column results in 4 rows defined in the "ColumnPosition" order:

"UniqueFlag" = "Y" indicates a unique index

"IndexType" indicates how it was defined in the Create table: 'K' = primary key, 'U' = unique constraint, 'P' = primary index, 'S' = secondary index

dbc.All_ri_childrenV contains specific FKs.

If for one table there is only "HELP INDEX my_table" for indexes, but in this case I prefer "SHOW TABLE my_table", which returns the full source code.

+8
source

Source: https://habr.com/ru/post/1491941/


All Articles