oracle 中查看一张表是否有主键,主键在哪个字段上的语句怎么查如要查aa表,请写两句分别回答

如题所述

select a.constraint_name, a.column_name
from user_cons_columns a, user_constraints b
where a.constraint_name = b.constraint_name
and b.constraint_type = 'P'
and a.table_name = 'AA'-------大写
查看AA表的主键约束名称,以及主键约束的字段名称。
如果没有,则返回空
温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-05-25
SQL> select owner,constraint_name,CONSTRAINT_TYPE,table_name from user_constraints;

OWNER CONSTRAINT_NAME C TABLE_NAME
------------------------------ ------------------------------ - -----------------------
SCOTT PK_DEPT P DEPT
SCOTT PK_EMP P EMP
SCOTT FK_DEPTNO R EMP
相似回答