How to find a primary key in teradata tables?
Teradata Teradata Discussion Forums Teradata.com Discussion Forum
Visit Teradata.com
Home       Guidelines    Member List
Welcome Guest ( Login | Register )
        


This online forum is for user-to-user discussions of Teradata products, and is not an official customer support channel for Teradata. If you require direct assistance, please contact Teradata support.


How to find a primary key in teradata tables?... Expand / Collapse
Author
Message
Posted 5/15/2009 2:26:31 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 6/18/2009 11:48:19 PM
Posts: 2, Visits: 4
Hi,
Actually,I am new to this teradata but i know basic concepts.

we will create indexes when we create tables in teradata and will not mention primary keys.
how to find a primary key in existing teradata table?

Please let me know the solution.


suni
Post #15438
Posted 5/15/2009 4:53:23 AM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 10/8/2009 1:16:14 PM
Posts: 79, Visits: 105
Hi,



While creating a table if we specify Primary Key then this will be created as either UPI or USI.(If we are not specified any PI, then PK will be chosen as PI ie., UPI, else USI).



you can also use DBC views (Indices) to identify the type.



Regards,

Balamurugan
Post #15440
Posted 5/15/2009 9:30:54 AM
Forum Member

Forum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum MemberForum Member

Group: Forum Members
Last Login: 7/29/2009 9:23:21 AM
Posts: 27, Visits: 34
Primary Keys can be enforced with by unique indexes or by using a UNIQUE or PRIMARY KEY constraint on the table. The first goal of your Primary Index is to identify the best access path to the data and/or join strategy in the overall data model not necessarily to enforce the integrity of the data in the table.

There are tables in DBC that will help you identify both indexes and table constraints.
Post #15443
Posted 5/15/2009 11:49:18 AM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 11/12/2009 10:59:03 AM
Posts: 23, Visits: 24
If you show the definition of the table either by right clicking on the table listed in the tree view or type SHOW TABLE dbname.tablename;
it will display the definition of the table with all indices including the default one which was created automatically.

Thanks,
Uma
Post #15445
Posted 5/15/2009 6:42:53 PM
Supreme Being

Supreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme BeingSupreme Being

Group: Forum Members
Last Login: 7/10/2009 6:28:52 PM
Posts: 505, Visits: 546
As a practice, database is not the right place to sort out what is the primary key of the table, that should be maintained in the data model.

If you explicitly define a primary key in the table definition, teradata will maintain it with indextype = 'K' in the DBC.Indices view.

Otherwise you are stuck to looking for unique indexes via uniquenessflag = 'y' in dbc.indices ( club on the index number for composite indexes) ...

So what will you do if there are two unique indexes in the table ? .... that's why it's better off maintained in the model.

Post #15447
Posted 9/28/2009 2:26:33 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: Forum Members
Last Login: 11/5/2009 6:07:39 AM
Posts: 9, Visits: 10
In order to find the Primary key in a table,
Condition for Primary Key:
* the column should be not-null
* it should give unique record
Suppose, we are having 10 columns in a table(dw_users). choose one not-null column for eg:user_id column in dw_users table.
Query to find P.K
-------------------
sel user_id,count(*) from dw_users group by 1 having count(*)>1 -- give unique record means user_id is the P.k for this table.
Post #16950
Posted 9/28/2009 10:29:20 AM
Junior Member

Junior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior MemberJunior Member

Group: Forum Members
Last Login: 10/5/2009 12:34:37 PM
Posts: 10, Visits: 26
Hello,
PI and PK are different. You dont have to look for PK in physical database design cos PK is a logical datamodel term to uniquely identify a row , whereas PI is a physical database design term and it is used by amp to access/distribute rows to teradata DB.
The below sql may be handy to guess your PK though :
sel colname ,count(*) from DB.tablename group by 1 having count(*)>1

note: you need to try out different combo of columns if your PK is a composite one.


Cheers,
Samp
Post #16955
« Prev Topic | Next Topic »


Reading This Topic Expand / Collapse
Active Users: 0 ( 0 guests, 0 members, 0 anonymous members )
No members currently viewing this topic.


All times are GMT -5:00, Time now is 10:31pm

Powered By InstantForum.NET v4.1.4 © 2009
Execution: 0.156. 9 queries. Compression Disabled.