Thursday, July 28, 2011

Primary Key

Steps of find the type of Primary Key Involved :

1. Find out the type of the object

select object_name, object_type from all_objects where object_name = upper('<p_object_name>');

2. To fetch the primary key name corresponding to the index/table name from the error message.

Index

select primary_key_name
from fnd_primary_keys
where application_id=283
and table_id = (select table_id from fnd_indexes
where application_id=283 and index_name = upper('<p_object_name>'));

or

Table

select primary_key_name
from fnd_primary_keys
where application_id=283
and table_id = (select table_id from fnd_tables
where application_id=283 and table_name = upper('<p_object_name>'));

3. Check the involved primary key
select primary_key_type
from fnd_primary_keys where primary_key_name = upper('<p_primary_key_name>');


To get Primary Keys info on set of tables:

select pk.primary_key_type TYPE,
pk.application_id APPID,
pk.primary_key_name
from fnd_primary_keys pk,fnd_tables t
where t.application_id >= 0
and t.table_name in ('ABC','DEF',
'GHI','KLM')
and pk.application_id = t.application_id
and pk.table_id = t.table_id;

TYPE    APPID         PRIMARY_KEY_NAME             
____   _______         ___________________    
S           123             PQR_PK    
D           123             LMN_PK
D           123             XYZ_PK 
D           123             123_PK

If in case required to change/update the type of  key

UPDATE fnd_primary_keys
SET primary_key_type = 'D'
WHERE primary_key_name = upper('PQR_PK');

COMMIT;

UR's Key Run ;-) 

No comments:

Post a Comment