How can I view the primary key of a table in Oracle?

There are two ways to view the primary key of a table.

  1. Use the DESCRIBE command:
DESCRIBE table_name;
  1. Use the following query to view the primary key of the table:
SELECT cols.table_name, cols.column_name, cols.position, cons.status
FROM all_constraints cons, all_cons_columns cols
WHERE cols.table_name = 'table_name'
AND cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
ORDER BY cols.position;

In the above query statement, replace ‘table_name’ with the name of the table you want to view. This will display the primary key column and its position in the table.

 

More tutorials

BroadcastReceiver Example Tutorial on Android(Opens in a new browser tab)

Tutorial on how to set up a Hibernate Tomcat JNDI DataSource.(Opens in a new browser tab)

QR code generator in Java using zxing.(Opens in a new browser tab)

Java thread ensuring Java code is thread-safe(Opens in a new browser tab)

Spring MVC HandlerInterceptorAdapter and HandlerInterceptor.(Opens in a new browser tab)

How can an Oracle table’s primary key be deleted?(Opens in a new browser tab)

How to display data in a DataGridView table?(Opens in a new browser tab)

What are the functions of the fwrite function in the C language?(Opens in a new browser tab)

The program in Java for displaying “Hello World”(Opens in a new browser tab)

How is time series data stored and queried in Cassandra?(Opens in a new browser tab)

 

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds