Need to identigy Primary key from a table using Select

Database
Enthusiast

Need to identigy Primary key from a table using Select

Hi,

I was trying to identify the Primary keys from a table. I can do
show table tablename or help table tablename which would give me details about whole tables. Is it some command available to display PK or FK columns defined in a table

Thanks,
Rishab
3 REPLIES
Enthusiast

Re: Need to identigy Primary key from a table using Select

Rishab,
There is nothing like a primary key in the tables.
This is logical term, you will find this in sqlserver or oracle, but not in Teradata.

you will find primary Index wich has nothing to do with primary key.

if you create a Unique index on a table (or if you find one for a table) that can be considered as primary key.

Junior Contributor

Re: Need to identigy Primary key from a table using Select

Hi Rishab,
if the table was created with a Primary Key constraint, it has been replaced by a UPI/USI.
There's a PrimaryKeyIndexId in dbc.tables, which indicates the original PK and relates to dbc.indices.IndexNumber.
In current releases there's also a "K" in dbc.indices.Indextype for a PK.

For FKs there's dbc.all_ri_children

Dieter
Enthusiast

Re: Need to identigy Primary key from a table using Select

Thank you very much Dieter for the post.
I am sorry for the answer i gave. Good to know this info.