Skip to content
Advertisement

SQL query to find Primary Key of a table?

How can I find which column is the primary key of a table by using a query?

Advertisement

Answer

For Oracle, you can look it up in the ALL_CONSTRAINTS table:

DEMO.

For SQL Server, it was already answered here, and for MySQL check @ajon’s answer.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement