如何在Oracle 11g中查询主键 [英] How to query for a primary key in oracle 11g
本文介绍了如何在Oracle 11g中查询主键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道如何在Oracle 11g中查询表的主键吗?我对于SQL Server看到了类似的问题,但是尝试在该线程上回答问题并没有运气.
Does anybody know how to query for a primary key of a table in Oracle 11g? I saw a similar question for SQL Server, but I've had no luck from trying the answers on that thread.
谢谢!
推荐答案
作为拥有表的用户,您可以执行以下操作:
As the user that owns the table you can do:
select constraint_name, status, deferrable, deferred, validated, generated
from user_constraints
where constraint_type = 'P' and table_name = 'Table Name'
更新:我认为这可以满足您的需求.
Update: I think this gets you what you need.
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 = 'Table Name'
AND cons.constraint_type = 'P'
AND cons.constraint_name = cols.constraint_name
AND cons.owner = cols.owner
ORDER BY cols.table_name, cols.position
您可以访问此网站以获取更多详细信息.
You can check this site for more details.
这篇关于如何在Oracle 11g中查询主键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文