日期:2014-05-17  浏览次数:20908 次

Oracle 10g sqlplus下如何查看table的primary key呢?

Oracle   10g   sqlplus下如何查看table的primary   key呢?  

Example:  
SQL>   create   table   test(
    2         id1   number   primary   key,
    3         id2   number,
    4         id3   number
    5     );
SQL>   describe   test;
  Name                                                                       Null?           Type
  --------------------------------------   -----------   ---------------------
  ID1                                                                       NOT   NULL     NUMBER
  ID2                                                                                                 NUMBER
  ID3                                                                                                 NUMBER


------解决方案--------------------
SELECT table_name, constraint_name, constraint_type
FROM sys.user_constraints
WHERE table_name= 'test '

看看是不是出来了?
------解决方案--------------------

select uc.TABLE_NAME,ucc.COLUMN_NAME
from user_constraints uc,user_cons_columns ucc WHERE uc.CONSTRAINT_NAME = ucc.CONSTRAINT_NAME and uc.TABLE_NAME=upper( 'tt1_record ')
and constraint_type= 'P '