Query to check primary key in a table in Oracle

If you want to know the Primary Keys in a particular table, run the below query by replacing Tablename with the actual table name.

SELECT cols.table_name, cols.column_name, cols.position, cons.status, cons.owner
FROM all_constraints cons, all_cons_columns cols
WHERE cols.table_name = 'TableName'
AND cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
ORDER BY cols.table_name, cols.position;
For Dotnet Projects and Interview Questions, Click here.

0 comments:

Post a Comment

top