Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5951927
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T17:36:28+00:00 2026-05-22T17:36:28+00:00

In a DB2 federated database (based on remote servers and nicknames), I need to

  • 0

In a DB2 federated database (based on remote servers and nicknames), I need to clean up the model and recreate it from another database. I need to delete every database object except those servers and nicknames.

I know how to retrieve the list of objects from the SYSCAT schema. Now I need to run the DROP statements on each. Obviously the dependencies will get in the way.

The brute force approach would be to run the DROPs in a loop until all have succeeded, but depending on the order (lucky or not), it could take a very long time.

Would you know a way to efficiently order the DROP statement so that the total time for the deletion is the shortest possible?

A perfect solution is not expected. A reasonably clever solution is good enough.

Thank you

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T17:36:29+00:00Added an answer on May 22, 2026 at 5:36 pm

    This query is able to order the statements according to the total number of elements they depend on. The resulting order works almost without a glitch, the second pass of the “brute force” approach contains only a handful of objects (out of several thousands objects to delete).

    Problem, it is very slow…

    EDIT : There was a typo in the query that made it return more or less correct data but very very slowly.

    WITH FIRST_LEVEL_DEPENDENCIES (BSCHEMA, BNAME, DTYPE, DSCHEMA, DNAME) AS
    (
      SELECT T1.TABSCHEMA AS BSCHEMA, T1.TABNAME AS BNAME, T1.BTYPE, T1.BSCHEMA, T1.BNAME
        FROM SYSCAT.TABDEP T1
       WHERE T1.TABSCHEMA NOT LIKE 'SYS%'
         AND T1.BTYPE <> 'N'
       UNION ALL
      SELECT T1.ROUTINESCHEMA AS BSCHEMA, T1.SPECIFICNAME AS BNAME, T1.BTYPE, T1.BSCHEMA, T1.BNAME
        FROM SYSCAT.ROUTINEDEP T1
       WHERE T1.ROUTINESCHEMA NOT LIKE 'SYS%'
         AND T1.BTYPE <> 'N'
       UNION ALL
      SELECT T1.TABSCHEMA AS BSCHEMA, T1.TABNAME AS BNAME, 'T', T1.REFTABSCHEMA, T1.REFTABNAME
        FROM SYSCAT.REFERENCES T1
       WHERE T1.TABSCHEMA NOT LIKE 'SYS%'
    ),
    RECURSIVE_DEPENDENCIES (LEVEL, BSCHEMA, BNAME, DTYPE, DSCHEMA, DNAME) AS
    (
       SELECT 1, U.BSCHEMA, U.BNAME, U.DTYPE, U.DSCHEMA, U.DNAME
         FROM FIRST_LEVEL_DEPENDENCIES AS U
        UNION ALL
       SELECT LEVEL + 1, REC.BSCHEMA, REC.BNAME, U.DTYPE, U.DSCHEMA, U.DNAME
         FROM RECURSIVE_DEPENDENCIES REC,
              FIRST_LEVEL_DEPENDENCIES U
        WHERE LEVEL < 6
          AND U.BSCHEMA = REC.DSCHEMA
          AND U.BNAME = REC.DNAME
    )
    SELECT BSCHEMA, BNAME, COUNT(*)
      FROM RECURSIVE_DEPENDENCIES
     GROUP BY BSCHEMA, BNAME
     ORDER BY COUNT(*)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to access DB2 database in plain standalone Java project. I cannot use
In DB2 , I need to do a SELECT FROM UPDATE , to put
Database: DB2 v9.5 on AIX Scenario: I have 2 instances- db2inst1 and db2inst2. I
I have a db2 database file, but do not have a db2 server. I
Just getting started with db2. Quick question about giving it SQL commands from a
I have a (DB2) database table containing location information, one column of which is
I have an existing DB2 database at my job. (At least, I think it's
In DB2, using the following left join select a.deptno, a.deptname, b.empno from #dept a
From a DB2 table I've got blob which I'm converting to a byte array
I am using command db2 restore db S18 from /users/intadm/s18backup/ taken at 20110913113341 on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.