Re: Creating a heirarchy of tables in a schema based on FK
- From: Steve Baldwin <stbaldwin@xxxxxxxxxxxxxxxx>
- To: Steven.Rebello@xxxxxxxxxx
- Date: Wed, 18 Nov 2009 19:12:50 +1100
Could you just change the FK constraints to 'ON DELETE CASCADE' then
just delete from the top level table(s)? This is by far the least
amount of work.
Alternatively, you could write a recursive function that fetches from
user_constraints and user_cons_columns and uses either dbms_sql or
execute immediate (depending on your Oracle version) to execute the
delete statement.
Hope this helps.
On Wed, Nov 18, 2009 at 6:30 PM, Steven Rebello
<Steven.Rebello@xxxxxxxxxx> wrote:
> Hi List members
>
> Would like your help/inputs in a problem I am facing here.
>
> I want to clear out records from a huge bunch of selected tables (1000+)
> which have interdependencies established using FK constraints. Of course,
> just creating a "delete * from table" doesn't work because of the FK
> constraints.
>
> What I want to do is to identify the "child" tables which can be deleted
> first and then create the hierarchy of tables so that the parent tables can
> then be cleared out, and so on.
>
> Can anyone point me to any reference or script which can generate this
> hierarchy based on the foreign key constraints? Based on that I can then make
> the delete script pretty quickly.
>
> I thought of disabling the constraints and re-enabling them after the "delete
> * from table" script, but would like to try the cleaner approach of starting
> from the bottom of the dependency tree for these tables.
>
> Thanks
> Steven Rebello
> MASTEK LTD.
> Mastek is in NASSCOM's 'India Top 20' Software Service Exporters List.
> In the US, we're called MAJESCOMASTEK
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> Opinions expressed in this e-mail are those of the individual and not that of
> Mastek Limited, unless specifically indicated to that effect. Mastek Limited
> does not accept any responsibility or liability for it. This e-mail and
> attachments (if any) transmitted with it are confidential and/or privileged
> and solely for the use of the intended person or entity to which it is
> addressed. Any review, re-transmission, dissemination or other use of or
> taking of any action in reliance upon this information by persons or entities
> other than the intended recipient is prohibited. This e-mail and its
> attachments have been scanned for the presence of computer viruses. It is the
> responsibility of the recipient to run the virus check on e-mails and
> attachments before opening them. If you have received this e-mail in error,
> kindly delete this e-mail from desktop and server.
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>
> --
> http://www.freelists.org/webpage/oracle-l
>
>
>
--
http://www.freelists.org/webpage/oracle-l
Other related posts: