[Oracle]Oracle中查询该表中的主键被哪些表引用,该表中的外键来源于哪些表
程序员文章站
2022-06-05 12:18:16
...
Oracle中查询该表中的主键被哪些表引用的SQL语句:
select c.TABLE_NAME
from all_constraints p, all_constraints c
where p.table_name = '表名'
and p.OWNER = SYS_CONTEXT('USERENV', 'CURRENT_SCHEMA')
and c.OWNER=SYS_CONTEXT('USERENV', 'CURRENT_SCHEMA')
and c.constraint_type = 'R'
and p.CONSTRAINT_NAME = c.R_CONSTRAINT_NAME
Oracle中查询该表中的外键来源于哪些表的SQL语句:
select cl.table_name
from user_cons_columns cl
left join user_constraints c
on cl.constraint_name = c.r_constraint_name
where c.constraint_type = 'R'
and c.table_name = '表名'
PS:查询owner的SQL语句: select SYS_CONTEXT(‘USERENV’, ‘CURRENT_SCHEMA’) from dual
上一篇: javascript与PHP动态往类中添加方法对比
下一篇: 查询哪些表没有聚集索引