IBM Mainframe Forum Index
 
Log In
 
IBM Mainframe Forum Index Mainframe: Search IBM Mainframe Forum: FAQ Register
 

selecting all tables with common column name


IBM Mainframe Forums -> DB2
Post new topic   Reply to topic
View previous topic :: View next topic  
Author Message
gaansin

New User


Joined: 25 Apr 2007
Posts: 1
Location: chennai

PostPosted: Wed Jun 27, 2007 4:00 pm
Reply with quote

i want to select all the tables in databse which is haveing some common column name. say example i want to select all the tables in the data base which is having column name empnumber. please help on this
Back to top
View user's profile Send private message
Craq Giegerich

Senior Member


Joined: 19 May 2007
Posts: 1512
Location: Virginia, USA

PostPosted: Wed Jun 27, 2007 6:40 pm
Reply with quote

gaansin wrote:
i want to select all the tables in databse which is haveing some common column name. say example i want to select all the tables in the data base which is having column name empnumber. please help on this


This should give you a starting point.
Code:
  SELECT                                               
   C.TBNAME, C.COLNO,                                   
   C.NAME,                                             
   CASE C.COLTYPE                                       
    WHEN 'DATE'     THEN 'DATE'                         
    WHEN 'TIME'     THEN 'TIME'                         
    WHEN 'TIMESTMP' THEN 'TIMESTAMP'                   
    WHEN 'SMALLINT' THEN 'SMALLINT'                     
    WHEN 'INTEGER'  THEN 'INTEGER'                     
    WHEN 'CHAR'     THEN                               
     'CHAR(' CONCAT STRIP(CHAR(C.LENGTH)) CONCAT ')'   
    WHEN 'DECIMAL'  THEN                               
     'DEC(' CONCAT STRIP(CHAR(C.LENGTH)) CONCAT ','     
      CONCAT STRIP(CHAR(C.SCALE)) CONCAT ')'           
    WHEN 'VARCHAR'  THEN                               
     'VARCHAR(' CONCAT STRIP(CHAR(C.LENGTH)) CONCAT ')'
    ELSE '???'                                         
    END AS FORMAT,                                     
    CASE C.NULLS                                       
     WHEN 'N' THEN ' '                                 
     WHEN 'Y' THEN 'YES'                     
    END AS NULLS                             
FROM SYSIBM.SYSCOLUMNS C, SYSIBM.SYSTABLES T 
  WHERE C.TBNAME = T.NAME                     
    AND T.DBNAME = 'XXXXXXXX'                 
ORDER BY 1, 2                                 
FOR FETCH ONLY;                     
Back to top
View user's profile Send private message
Phrzby Phil

Senior Member


Joined: 31 Oct 2006
Posts: 1042
Location: Richmond, Virginia

PostPosted: Wed Jun 27, 2007 6:55 pm
Reply with quote

"Select" is a SQL term. I presume you mean determine or find out which tables in a given database have a given column name.

Query the system table sysibm.syscolumns C joined with sysibm.systables T on C.TBNAME = T.NAME where C.NAME = 'EMPNUMBER' and T.DBNAME = <database name>. The column with your desired table names is C.TBNAME.
Back to top
View user's profile Send private message
vini_srcna

Active User


Joined: 26 May 2005
Posts: 178
Location: Copenhagen, Denmark

PostPosted: Thu Jun 28, 2007 9:42 am
Reply with quote

Just query the catalog SYSIBM.SYSCOLUMNS.

Select * FROM SYSIBM.SYSCOLUMNS WHERE NAME = 'colname'.

It will give the list of all the tables/views containing a column by this name.
Back to top
View user's profile Send private message
bhushan.shete

New User


Joined: 14 Nov 2006
Posts: 17

PostPosted: Thu Jun 28, 2007 5:36 pm
Reply with quote

hi...

really gud ques..

i hav some access prob....

sooner i wil come wit exact answer

Bhush
Back to top
View user's profile Send private message
bhushan.shete

New User


Joined: 14 Nov 2006
Posts: 17

PostPosted: Thu Jun 28, 2007 5:37 pm
Reply with quote

hi...

really gud ques..

but none of the posts reflect correct ans.

i hav some access prob.... sooner i wil come wit exact answer

Bhush
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic View Bookmarks
All times are GMT + 6 Hours
Forum Index -> DB2

 


Similar Topics
Topic Forum Replies
No new posts Replacing 'YYMMDD' with date, varying... SYNCSORT 3
No new posts How to load to DB2 with column level ... DB2 6
No new posts RC query -Time column CA Products 3
No new posts first column truncated in search result IBM Tools 13
No new posts Need to fetch data from so many DB2 t... DB2 9
Search our Forums:

Back to Top