View previous topic :: View next topic
|
Author |
Message |
dmithunibm
New User
Joined: 23 May 2007 Posts: 18 Location: Bangalore
|
|
|
|
Hi All,
Can anyone tell me whether there is sql query to get column names of a particular table or not?
Thanks in advance. |
|
Back to top |
|
|
the_gautam
Active User
Joined: 05 Jun 2005 Posts: 165 Location: Bangalore
|
|
|
|
Code: |
SELECT A.NAME, A.CREATOR, A.TYPE, A.TBCREATOR, A.TBNAME, B.NAME, BO.COLTYPE, B.LENGTH, B.SCALE FROM SYSIBM.SYSTABLES A, SYSIBM.SYSCOLUMNS B WHERE A.CREATOR=<user id> AND A.NAME=B.TBNAME AND A.CREATOR=B.TBCREATOR; |
This query gives the details of the columns under a particular user-id. Play with it to meet your requirement. |
|
Back to top |
|
|
dmithunibm
New User
Joined: 23 May 2007 Posts: 18 Location: Bangalore
|
|
|
|
Hi Gautam,
Thanks a lot. |
|
Back to top |
|
|
ksk
Active User
Joined: 08 Jun 2006 Posts: 355 Location: New York
|
|
|
|
Hi,
To get the coloumn names of a particular table, execute select query and extract only one row. you will get all the colomn names.
SELECT * from Table-Name
fetch first row only; |
|
Back to top |
|
|
dmithunibm
New User
Joined: 23 May 2007 Posts: 18 Location: Bangalore
|
|
|
|
Hi ksk,
I need just the name of the columns.In this case one record would also be fetched from the table along with the column list. |
|
Back to top |
|
|
Anuj Dhawan
Superior Member
Joined: 22 Apr 2006 Posts: 6250 Location: Mumbai, India
|
|
|
|
Hi,
If you need only the column-names, use any false condition such as
Code: |
SELECT * FROM TABLE-NAME
WHERE 1=2
WITH UR; |
it'll return only the column names; in QMF you can use function key "PF6" to "draw" the table. (If this is not the key, check the functioning of keys at the bottom of the screen in QMF, they are usually listed there.) |
|
Back to top |
|
|
ksk
Active User
Joined: 08 Jun 2006 Posts: 355 Location: New York
|
|
|
|
Yes, if you give a condition which never satisfies, you will get only colomn names.
Gautam,
Can we retreive required colomn names for a particular table with your query? |
|
Back to top |
|
|
dmithunibm
New User
Joined: 23 May 2007 Posts: 18 Location: Bangalore
|
|
|
|
Yes,that's what Anuj said. |
|
Back to top |
|
|
the_gautam
Active User
Joined: 05 Jun 2005 Posts: 165 Location: Bangalore
|
|
|
|
Yes why not, see the output of the query and restrict the rows returned by putting the table-names or user-id in the WHERE clause. You may, choose the fields to be returned as per your requirement. |
|
Back to top |
|
|
am_ne
New User
Joined: 24 Mar 2007 Posts: 25 Location: Bangalore
|
|
|
|
If you know the table name and the creator name then you can query SYSIBM.SYSCOLUMNS catalog table by using predicate TBNAME = 'table name' and TBCREATOR = 'creator'. |
|
Back to top |
|
|
|