Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

DB2 "describe" table ?

1,129 views
Skip to first unread message

Timothy Martin

unread,
Dec 1, 2002, 8:17:28 AM12/1/02
to
Is there any way to see what tables look like via SQL ? In MySQL
I can use the SQL statement "describe", but that doesn't seem to
work with DB2.

=============================================================================
[db2inst1@buffy tmartin]$ db2 list tables

Table/View Schema Type Creation time
------------------------------- --------------- ----- --------------------------
CL_SCHED DB2INST1 T 2002-12-01-11.34.25.262670
DEPARTMENT DB2INST1 T 2002-12-01-11.34.07.107148
EMP_ACT DB2INST1 T 2002-12-01-11.34.10.537600
EMP_PHOTO DB2INST1 T 2002-12-01-11.34.16.575583
EMP_RESUME DB2INST1 T 2002-12-01-11.34.21.362912
EMPLOYEE DB2INST1 T 2002-12-01-11.34.07.690746
IN_TRAY DB2INST1 T 2002-12-01-11.34.25.350675
ORG DB2INST1 T 2002-12-01-11.34.02.202452
PROJECT DB2INST1 T 2002-12-01-11.34.15.216740
SALES DB2INST1 T 2002-12-01-11.34.22.944956
STAFF DB2INST1 T 2002-12-01-11.34.04.665088

11 record(s) selected.

[db2inst1@buffy tmartin]$ db2 describe ORG
SQL0104N An unexpected token "ORG" was found following "DESCRIBE". Expected
tokens may include: "SELECT". SQLSTATE=42601
[db2inst1@buffy tmartin]$

Lennart Jonsson

unread,
Dec 1, 2002, 9:46:12 AM12/1/02
to

db2 describe table db2inst1.org


/Lennart


Larry Menard

unread,
Dec 2, 2002, 2:27:51 PM12/2/02
to
"describe table ..." is a command, not SQL. To use SQL, you'd need to
query the system catalogs: "select ..., ... from syscat.tables where tabname
...".

--
Larry Menard
IBM Workstation Database (DB2) Performance Team
Defender of Geese and of All Things Natural


"Lennart Jonsson" <lel...@bonetmail.com> wrote in message
news:asd7b8$q3pds$1...@ID-167942.news.dfncis.de...

Doug Doole

unread,
Dec 2, 2002, 3:18:13 PM12/2/02
to
I find it easier to describe a table from SQL as follows:
stmt="SELECT * FROM tabname"
EXEC SQL PREPARE s FROM :stmt
EXEC SQL DESCRIBE s INTO :*da

Then you walk the SQLDA to determine the column information.

Karl Hanson

unread,
Dec 2, 2002, 4:33:10 PM12/2/02
to
Larry Menard wrote:
>
> "describe table ..." is a command, not SQL. To use SQL, you'd need to
> query the system catalogs: "select ..., ... from syscat.tables where tabname
> ...".
>
> --
> Larry Menard
> IBM Workstation Database (DB2) Performance Team
> Defender of Geese and of All Things Natural
>
> "Lennart Jonsson" <lel...@bonetmail.com> wrote in message
> news:asd7b8$q3pds$1...@ID-167942.news.dfncis.de...
> > On Sun, 01 Dec 2002 05:17:28 +0000, Timothy Martin wrote:
> >
> > > Is there any way to see what tables look like via SQL ? In MySQL
> > > I can use the SQL statement "describe", but that doesn't seem to
> > > work with DB2.
> > >
< snip >

It depends on the platform.. eg DB2 UDB for iSeries does support
DESCRIBE TABLE as an SQL statement:
http://publib.boulder.ibm.com/iseries/v5r2/ic2924/info/db2/rbafzmstdescrtb.htm#HDRDESCRTB

--
Karl Hanson

Trent

unread,
Dec 2, 2002, 6:43:17 PM12/2/02
to
Hello, Lennart.

Try this
db2 describe select * from tablename

Trent

0 new messages