I want to list all the tables which my foriegn-key constrainsts are
renferencing to. I tried to list the dba views that are associated
with constrainsts and
SELECT DISTINCT ac.owner, ac.table_name
FROM ALL_CONSTRAINTS ac
WHERE ac.constraint_type IN ('P','U')
AND EXISTS (SELECT NULL FROM ALL_CONSTRAINTS
WHERE constraint_type = 'R'
AND r_owner = ac.owner
AND r_constraint_name = ac.constraint_name);
Jurij Modic ASCII a stupid question, get a stupid ANSI
24 hours in a day .... 24 beer in a case .... coincidence?
Originally posted by jmodic More something like that:
Code:
SELECT DISTINCT ac.owner, ac.table_name
FROM ALL_CONSTRAINTS ac
WHERE ac.constraint_type IN ('P','U')
AND EXISTS (SELECT NULL FROM ALL_CONSTRAINTS
WHERE constraint_type = 'R'
AND r_owner = ac.owner
AND r_constraint_name = ac.constraint_name);
Same thing :-) You only list additionally the owner.
Oracle Certified Master
Oracle Certified Professional 6i,8i,9i,10g,11g
email: ocp_9i@yahoo.com
Originally posted by julian Same thing :-) You only list additionally the owner.
Er, no. You must use ALL_CONSTRAINTS, not USER_CONSTRAINTS - at least in your outer query. Because PK and UK constraints that tables from your schema are referencing might not be in your own schema, no? Otherwise your query might return too few tables, or some of them might simply be the wrong ones.
Last edited by jmodic; 06-16-2004 at 07:39 AM.
Jurij Modic ASCII a stupid question, get a stupid ANSI
24 hours in a day .... 24 beer in a case .... coincidence?
Originally posted by jmodic Er, no. You must use ALL_CONSTRAINTS, not USER_CONSTRAINTS - at least in your outer query. Because PK and UK constraints that tables from your schema are referencing might not be in your own schema, no? Otherwise your query might return too few tables, or some of them might simply be the wrong ones.
Yes, that's right, there might be interschema constraints. Although I have never seen that in a real database :-)
Oracle Certified Master
Oracle Certified Professional 6i,8i,9i,10g,11g
email: ocp_9i@yahoo.com
e.g. EMP_DEPTS_FK (or even 'empdeptno_deptsdeptno_fk') for a foreign key on EMP.dept_no referencing DEPTS.dept_no. Then, usually, at a glance you can identify the objects involved.
Oracle doesn't have "GRANT REFERENCES ON xy TO wz;" just for looking nicer. Some are actualy using this and having interschema constraints is nothing unusual.
Jurij Modic ASCII a stupid question, get a stupid ANSI
24 hours in a day .... 24 beer in a case .... coincidence?
Bookmarks