查询表上的约束

来源:互联网 发布:刚开始做淘宝卖什么好 编辑:程序博客网 时间:2024/06/05 22:38

一个表上可以有多个约束,一个约束又可以作用多个列,使用下面的SQL语句可以把这些信息一览无余。

select b.TABLE_NAME,b.CONSTRAINT_NAME,b.constraint_type,
 MAX (DECODE (POSITION, 1, column_name, NULL)) cname1, 
                 MAX (DECODE (POSITION, 2, column_name, NULL)) cname2, 
                 MAX (DECODE (POSITION, 3, column_name, NULL)) cname3, 
                 MAX (DECODE (POSITION, 4, column_name, NULL)) cname4, 
                 MAX (DECODE (POSITION, 5, column_name, NULL)) cname5, 
                 MAX (DECODE (POSITION, 6, column_name, NULL)) cname6, 
                 MAX (DECODE (POSITION, 7, column_name, NULL)) cname7, 
                 MAX (DECODE (POSITION, 8, column_name, NULL)) cname8,
                 b.r_owner,
                 b.r_constraint_name,
                 count(*) col_cnt from (
select constraint_name,
       table_name,
       column_name,
       position
  from user_cons_columns) a,user_constraints b
where a.constraint_name=b.CONSTRAINT_NAME
group by b.TABLE_NAME,b.CONSTRAINT_NAME,b.constraint_type,b.r_owner,b.r_constraint_name
order by b.table_name,b.constraint_name
/

 

0 0
原创粉丝点击