Board index » delphi » How to know from Delphi the Primary Key of a table in relational database

How to know from Delphi the Primary Key of a table in relational database

Hi

I need to know the manner to know the Primary key of a table ( Oracle or
DB2) ?

Thanks in advance

Marcelo Spak

 

Re:How to know from Delphi the Primary Key of a table in relational database


In Oracle:
select column_name from user_cons_columns where
constraint_name = (select constraint_name from user_constraints where
table_name =  'MYTABLE' and constraint_type = 'P'

John Pierce
-\

Re:How to know from Delphi the Primary Key of a table in relational database


Marcelo,

If your database servers are ANSI-92 compliant, then you might be able to
use the information_schema views , and do something like :

SELECT U.COLUMN_NAME FROM INFORMATION_SCHEMA.CONSTRAINT_COLUMN_USAGE U
JOIN INFORMATION_SCHEMA.TABLE_CONSTRAINTS C ON
U.CONSTRAINT_NAME = C.CONSTRAINT_NAME
WHERE C.TABLE_NAME = 'YourTableName'
AND C.CONSTRAINT_TYPE = 'PRIMARY KEY'

Quote
Marcelo Spak <ms...@kropol.com.ar> wrote in message

news:96eu22$5g91@bornews.inprise.com...
Quote

> I need to know the manner to know the Primary key of a table ( Oracle or
> DB2) ?

Other Threads