Check Oracle Table Primary Key: SQL Query Guide

To check if a table has a primary key in an Oracle database, you can run the following SQL query:

SELECT * 
FROM USER_CONSTRAINTS 
WHERE CONSTRAINT_TYPE = 'P' 
AND TABLE_NAME = 'your_table_name';

In the above query, replace ‘your_table_name’ with the name of the table you want to check. This SQL query will check if a primary key constraint exists in the specified table. If the query returns a result set, it means that the table has a primary key; otherwise, it means that the table does not have a primary key.

bannerAds