If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > SQL help needed

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-29-11, 06:49
ajh ajh is offline
Registered User
 
Join Date: Apr 2011
Posts: 31
Red face SQL help needed

There are 2 schemas/libararies in the database, A & B.
The qsys2.sysindexes table has column index_name and schema_name and contains all indexes for both schemas A & B.
The schema A has 183 indexes. The schema B has 1 index by name of idxemp which is in the schema A also.
I am looking for a query whic gives output showing me 182 indexes in schema A which are not in the schema B
I need this so that I can add missing indexes into schema B.


Thanks

Last edited by ajh; 04-29-11 at 09:02. Reason: Added Information
Reply With Quote
  #2 (permalink)  
Old 04-29-11, 08:45
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,195
I know a little about iSeries.

But, the query may be like this...
Code:
SELECT VARCHAR(index_schema , 10) AS index_schema
     , VARCHAR(index_name   , 30) AS index_name
     , VARCHAR(table_schema , 10) AS table_schema
     , VARCHAR(table_name   , 30) AS table_name
 FROM  qsys2.sysindexes si_a
 WHERE index_schema = 'SCHEMA A'
   AND NOT EXISTS
       (SELECT 0
         FROM  qsys2.sysindexes si_b
         WHERE si_b.index_schema = 'SCHEMA B'
           AND si_b.index_name   = si_a.index_name
;
Reply With Quote
  #3 (permalink)  
Old 04-29-11, 09:17
ajh ajh is offline
Registered User
 
Join Date: Apr 2011
Posts: 31
Red face Please Help

There are 2 schemas/libararies in the database, A & B.
The qsys2.sysindexes table has column index_name and schema_name and contains all indexes for both schemas A & B.
The schema A has 183 indexes. The schema B has 1 index by name of idxemp which is in the schema A also.
I am looking for a query whic gives output showing me 182 indexes in schema A which are not in the schema B
I need this so that I can add missing indexes into schema B.


Thanks
Reply With Quote
  #4 (permalink)  
Old 04-29-11, 09:35
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,195
Quote:
The schema A has 183 indexes. The schema B has 1 index by name of idxemp which is in the schema A also.
I am looking for a query whic gives output showing me 182 indexes in schema A which are not in the schema B
Are you kidding me?

What the problem in a query like this?
Code:
SELECT
       VARCHAR(index_name   , 30) AS index_name
     , VARCHAR(table_schema , 10) AS table_schema
     , VARCHAR(table_name   , 30) AS table_name
 FROM  qsys2.sysindexes
 WHERE index_schema =  'A'
   AND index_name   <> 'idxemp'
;
Reply With Quote
  #5 (permalink)  
Old 04-29-11, 09:41
ajh ajh is offline
Registered User
 
Join Date: Apr 2011
Posts: 31
Red face SQL Help

Quote:
Originally Posted by tonkuma View Post
Are you kidding me?

What the problem in a query like this?
Code:
SELECT
       VARCHAR(index_name   , 30) AS index_name
     , VARCHAR(table_schema , 10) AS table_schema
     , VARCHAR(table_name   , 30) AS table_name
 FROM  qsys2.sysindexes
 WHERE index_schema =  'A'
   AND index_name   <> 'idxemp'
;
thanks for your reply. Its an example that i have given to you.
The schema A actually has 183 indexes and schema B has 130.
Now 53 indexes out of 183 in the A schema are not in the schema B. Thats why the 53 indexes difference.
So i want a list of the 53 indexes in schema A that are not in Schema B.
Please Help.
Reply With Quote
  #6 (permalink)  
Old 04-29-11, 09:47
tonkuma tonkuma is offline
Registered User
 
Join Date: Feb 2008
Location: Japan
Posts: 2,195
I think that I already answered like this...

Code:
SELECT ...
...

 WHERE index_schema = 'SCHEMA A'
   AND NOT EXISTS
       (SELECT 0
...
Reply With Quote
  #7 (permalink)  
Old 04-29-11, 10:11
ajh ajh is offline
Registered User
 
Join Date: Apr 2011
Posts: 31
Smile Thanks

Thanks for your time and help i got it working fine using your guidance.
appreciation !!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On