Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1417285
  • 博文数量: 239
  • 博客积分: 5909
  • 博客等级: 大校
  • 技术积分: 2715
  • 用 户 组: 普通用户
  • 注册时间: 2010-07-24 20:19
文章分类

全部博文(239)

文章存档

2014年(4)

2013年(22)

2012年(140)

2011年(14)

2010年(59)

我的朋友

分类: Oracle

2013-10-11 10:18:50

查看table中的primary key

点击(此处)折叠或打开

  1. SELECT cols.table_name, cols.column_name, cols.position, cons.status, cons.owner
  2. FROM all_constraints cons, all_cons_columns cols
  3. WHERE cols.table_name = 'TABLE_NAME'
  4. AND cons.constraint_type = 'P'
  5. AND cons.constraint_name = cols.constraint_name
  6. AND cons.owner = cols.owner
  7. ORDER BY cols.table_name, cols.position;

查看user的所有的foreign key

点击(此处)折叠或打开

  1. SELECT a.constraint_name, a.table_name, a.column_name, c.owner,
  2.         c_pk.table_name r_table_name, b.column_name r_column_name
  3.    FROM user_cons_columns a
  4.    JOIN user_constraints c ON a.owner = c.owner
  5.         AND a.constraint_name = c.constraint_name
  6.    JOIN user_constraints c_pk ON c.r_owner = c_pk.owner
  7.         AND c.r_constraint_name = c_pk.constraint_name
  8.    JOIN user_cons_columns b ON C_PK.owner = b.owner
  9.         AND C_PK.CONSTRAINT_NAME = b.constraint_name AND b.POSITION = a.POSITION
  10.   WHERE c.constraint_type = 'R';


阅读(5130) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~