Re: Direct and indirect foreign key relationships in SQL or Pl/Sql

2002-12-20 Thread Jared . Still
Here's one way.

It uses a temporary table, as a CONNECT BY cannot be done on the 
%_CONSTRAINTS view.

Jared

create test data
--
drop table t3;
drop table t2;
drop table t1;

create table t1 ( pk number );
create table t2 ( pk number, t1_pk number );
create table t3 ( pk number, t2_pk number );
create table t4 ( pk number, t3_pk number );

alter table t1 add constraint t1_pk
primary key(pk);

alter table t2 add constraint t2_pk
primary key(pk);

alter table t3 add constraint t3_pk
primary key(pk);

alter table t4 add constraint t4_pk
primary key(pk);

alter table t2 add constraint t2_t1_pk
foreign key(t1_pk)
references t1(pk);

alter table t3 add constraint t3_t2_pk
foreign key(t2_pk)
references t2(pk);

alter table t4 add constraint t4_t3_pk
foreign key(t3_pk)
references t3(pk);

--
-- create temp table
drop table r1;

create global temporary table r1
on commit delete rows
--create table r1
as
select
c.table_name child
, p.table_name parent
, p.constraint_name
, c.constraint_name fk_constraint
, c.delete_rule
from dba_constraints c, dba_constraints p
where 1=0
/

insert into r1
select *
from
(
select
c.table_name child
, p.table_name parent
, p.constraint_name
, c.constraint_name fk_constraint
, c.delete_rule
from dba_constraints c, dba_constraints p
where c.owner = 'JKSTILL'
--and c.table_name like 'T%'
and c.constraint_type in ('R')
and c.status = 'ENABLED'
and p.owner = c.r_owner
and p.constraint_name = c.r_constraint_name
) a
/

--

-- report

col child format a10
col parent format a20
col pad format a20
col constraint_name format a30
col r_constraint_name format a30
col tlevel noprint

set line 120

select
tlevel
, parent
, constraint_name
, child
, fk_constraint
, delete_rule
from (
select
level tlevel
, lpad(parent, level*3) parent
, constraint_name
, child
, fk_constraint
, delete_rule
from r1
start with parent = 'T1'
connect by prior child = parent
)
order by tlevel
/






"Krishnaswamy, Ranganath" <[EMAIL PROTECTED]>
Sent by: [EMAIL PROTECTED]
 12/18/2002 11:13 PM
 Please respond to ORACLE-L

 
To: Multiple recipients of list ORACLE-L <[EMAIL PROTECTED]>
    cc: 
        Subject:Direct and indirect foreign key relationships in SQL or Pl/Sql


Hi all,

 How do I find out the direct and indirect foreign key 
relationships?
Say, for example there are four tables A, B, C and D of which A is the
parent table and B, C and D are child tables.  Say B and C are related to 
A
directly and D is related to A through C.  How do I find out this indirect
relationship apart from the direct relationships?  Any help in this regard
is very much appreciated. 

Thanks and Regards,

Ranganath

 
WARNING: The information in this message is confidential and may be 
legally
privileged. It is intended solely for the addressee.  Access to this 
message
by anyone else is unauthorised.  If you are not the intended recipient, 
any
disclosure, copying, or distribution of the message, or any action or
omission taken by you in reliance on it, is prohibited and may be 
unlawful.
Please immediately contact the sender if you have received this message in
error. Thank you.
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: Krishnaswamy, Ranganath
  INET: [EMAIL PROTECTED]

Fat City Network Services-- 858-538-5051 http://www.fatcity.com
San Diego, California-- Mailing list and web hosting services
-
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).




-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: 
  INET: [EMAIL PROTECTED]

Fat City Network Services-- 858-538-5051 http://www.fatcity.com
San Diego, California-- Mailing list and web hosting services
-
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).




Re: Direct and indirect foreign key relationships in SQL or Pl/Sql

2002-12-19 Thread Ruth Gramolini
Here is a script that I got from on of the lists.  It should do what you
want.
Ruth

select a.constraint_name, a.r_constraint_name, a.table_name, b.table_name
 from dba_constraints a,
dba_constraints b
where a.owner='YOUR_OWNER'
and a.R_CONSTRAINT_NAME  is not null
and a.R_constraint_name=b.constraint_name
order by a.table_name;


- Original Message -
To: "Multiple recipients of list ORACLE-L" <[EMAIL PROTECTED]>
Sent: Thursday, December 19, 2002 2:14 AM


> Hi all,
>
> How do I find out the direct and indirect foreign key relationships?
> Say, for example there are four tables A, B, C and D of which A is the
> parent table and B, C and D are child tables.  Say B and C are related to
A
> directly and D is related to A through C.  How do I find out this indirect
> relationship apart from the direct relationships?  Any help in this regard
> is very much appreciated.
>
> Thanks and Regards,
>
> Ranganath
>
>
> WARNING: The information in this message is confidential and may be
legally
> privileged. It is intended solely for the addressee.  Access to this
message
> by anyone else is unauthorised.  If you are not the intended recipient,
any
> disclosure, copying, or distribution of the message, or any action or
> omission taken by you in reliance on it, is prohibited and may be
unlawful.
> Please immediately contact the sender if you have received this message in
> error. Thank you.
> --
> Please see the official ORACLE-L FAQ: http://www.orafaq.net
> --
> Author: Krishnaswamy, Ranganath
>   INET: [EMAIL PROTECTED]
>
> Fat City Network Services-- 858-538-5051 http://www.fatcity.com
> San Diego, California-- Mailing list and web hosting services
> -
> To REMOVE yourself from this mailing list, send an E-Mail message
> to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
> the message BODY, include a line containing: UNSUB ORACLE-L
> (or the name of mailing list you want to be removed from).  You may
> also send the HELP command for other information (like subscribing).
>

-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: Ruth Gramolini
  INET: [EMAIL PROTECTED]

Fat City Network Services-- 858-538-5051 http://www.fatcity.com
San Diego, California-- Mailing list and web hosting services
-
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).




Re: Direct and indirect foreign key relationships in SQL or Pl/Sql

2002-12-19 Thread Dale
> How do I find out the direct and indirect foreign key relationships?
> Say, for example there are four tables A, B, C and D of which A is the
> parent table and B, C and D are child tables.  Say B and C are related to
A
> directly and D is related to A through C.  How do I find out this indirect
> relationship apart from the direct relationships?  Any help in this regard
> is very much appreciated.

The DataBee software has a Chain Finder tool in the Set Designer which
displays exactly this.  DataBee is designed to create referentially correct
subsets of Oracle databases and isn't free. However we do offer a 30 day
evaluation which might enable you to get done what you want to do. If you
would like to have a go at it drop me a note and I'll arrange to get an eval
key over to you.

Here's a link to the Chain Finder help page - it has a nice picture of the
relationship display.
http://www.databee.com/sdchainfinder.htm

Regards
Dale
-
Quickly and easily create test and development databases with DataBee.
http://www.DataBee.com


-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: 
  INET: [EMAIL PROTECTED]

Fat City Network Services-- 858-538-5051 http://www.fatcity.com
San Diego, California-- Mailing list and web hosting services
-
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).




Direct and indirect foreign key relationships in SQL or Pl/Sql

2002-12-18 Thread Krishnaswamy, Ranganath
Hi all,

How do I find out the direct and indirect foreign key relationships?
Say, for example there are four tables A, B, C and D of which A is the
parent table and B, C and D are child tables.  Say B and C are related to A
directly and D is related to A through C.  How do I find out this indirect
relationship apart from the direct relationships?  Any help in this regard
is very much appreciated.  

Thanks and Regards,

Ranganath


WARNING: The information in this message is confidential and may be legally
privileged. It is intended solely for the addressee.  Access to this message
by anyone else is unauthorised.  If you are not the intended recipient, any
disclosure, copying, or distribution of the message, or any action or
omission taken by you in reliance on it, is prohibited and may be unlawful.
Please immediately contact the sender if you have received this message in
error. Thank you.
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.net
-- 
Author: Krishnaswamy, Ranganath
  INET: [EMAIL PROTECTED]

Fat City Network Services-- 858-538-5051 http://www.fatcity.com
San Diego, California-- Mailing list and web hosting services
-
To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).