View Primary Key in PL/SQL: Quick Guide
You can view the primary key of a table in PL/SQL by using the following method:
Utilize the DESCRIBE command:
DESCRIBE table_name;
This command will display the structure of the table, including the primary key column and other important information.
Utilize the USER_CONSTRAINTS view:
SELECT constraint_name, constraint_type
FROM user_constraints
WHERE table_name = 'table_name';
This command will display all constraints for the specified table, including the primary key constraint. A constraint type of ‘P’ indicates a primary key constraint.
Utilizing the ALL_CONS_COLUMNS view:
SELECT column_name
FROM all_cons_columns
WHERE constraint_name = (SELECT constraint_name
FROM user_constraints
WHERE table_name = 'table_name'
AND constraint_type = 'P');
This command will display the primary key column names of the specified table.