Orcale query table information, primary key, combined primary key

Query table information

SELECT T.COLUMN_NAME,
       T.COLUMN_ID,
       T.NULLABLE,
       T.DATA_TYPE || '(' || T.DATA_LENGTH || ')' as DataType,
       T.DATA_DEFAULT as DATA_DEFAULT,
       C.COMMENTS
  FROM USER_TAB_COLUMNS T, USER_COL_COMMENTS C
 WHERE T.TABLE_NAME = C.TABLE_NAME
   AND T.COLUMN_NAME = C.COLUMN_NAME
   AND T.TABLE_NAME = '表名(大写)'
 order by t.COLUMN_ID

Query whether a table has a unique primary key

select cu.*
  from user_cons_columns cu, user_constraints au
 where cu.constraint_name = au.constraint_name
   and au.constraint_type = 'P'
   and au.table_name = '表名(大写)'

Query whether a table has a joint primary key

select cu.*
  from user_cons_columns cu, user_constraints au
 where cu.constraint_name = au.constraint_name
   and au.constraint_type = 'U'
   and au.table_name = '表名(大写)'

 

Guess you like

Origin blog.csdn.net/cs373616511/article/details/109053332