Geeks Talk

Prepare for your Next Interview




Query to get table structure

This is a discussion on Query to get table structure within the DB2 forums, part of the Databases category; Hi friends, i want a query to know the table structure in db2 listing all its columns, primary keys and all. I tried using the query describe table table_name i ...


Go Back   Geeks Talk > Databases > DB2

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 04-15-2008
Junior Member
 
Join Date: Sep 2007
Location: Bangalore
Posts: 13
Thanks: 1
Thanked 1 Time in 1 Post
Divya.B.V is on a distinguished road
Unhappy Query to get table structure

Hi friends, i want a query to know the table structure in db2 listing all its columns, primary keys and all. I tried using the query describe table table_name i get the following o/p --------------------- column type type name schema name length scale nulls ------------------------------ --------- ------------------ -------- ---- 0 record(s) selected. Sql0100w no row was found for fetch, update or delete; or the result of a query is an empty table. Sqlstate=02000 please help me.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-19-2008
Contributing Member
 
Join Date: Sep 2005
Posts: 53
Thanks: 3
Thanked 6 Times in 6 Posts
Beena is on a distinguished road
Re: Query to get table structure

The following example shows how to describe a SELECT statement:

db2 "describe output select * from staff" SQLDA Information

sqldaid :SQLDA sqldabc:896 sqln:20 sqld:7

Column Information

sqltype sqllen sqlname.data sqlname.length
-------------------- ------ ------------------------------ --------------
500 SMALLINT 2 ID 2
449 VARCHAR 9 NAME 4
501 SMALLINT 2 DEPT 4
453 CHARACTER 5 JOB 3
501 SMALLINT 2 YEARS 5
485 DECIMAL 7,2 SALARY 6
485 DECIMAL 7,2 COMM 4
Reply With Quote
  #3 (permalink)  
Old 04-20-2008
Junior Member
 
Join Date: Sep 2007
Location: Bangalore
Posts: 13
Thanks: 1
Thanked 1 Time in 1 Post
Divya.B.V is on a distinguished road
Smile Re: Query to get table structure

Quote:
Originally Posted by Beena View Post
The following example shows how to describe a SELECT statement:

db2 "describe output select * from staff" SQLDA Information

sqldaid :SQLDA sqldabc:896 sqln:20 sqld:7

Column Information

sqltype sqllen sqlname.data sqlname.length
-------------------- ------ ------------------------------ --------------
500 SMALLINT 2 ID 2
449 VARCHAR 9 NAME 4
501 SMALLINT 2 DEPT 4
453 CHARACTER 5 JOB 3
501 SMALLINT 2 YEARS 5
485 DECIMAL 7,2 SALARY 6
485 DECIMAL 7,2 COMM 4


Thanks Beena. Is there any query describing the primary keys of the table??
Reply With Quote
  #4 (permalink)  
Old 05-14-2008
Junior Member
 
Join Date: May 2008
Location: Burlington MA
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Jyelamanchili is on a distinguished road
Re: Query to get table structure

You can use describe indexes for table <<< table name>>> show detail thank you
Reply With Quote
  #5 (permalink)  
Old 05-26-2008
Junior Member
 
Join Date: May 2008
Location: Kolkata
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
dbadb2udb is on a distinguished road
Re: Query to get table structure

Hi,
As per my knowledge you have searched for the table which is not available.
If you use the bellow mentioned query then it will definitely work.
$ db2 "describe table schema-name.table-name"
Please check the table is cataloged or not...
Regards,
Shubhrojyoti
dbashubhrojyoti@gmail.com

Last edited by dbadb2udb : 05-26-2008 at 04:02 PM.
Reply With Quote
Reply

  Geeks Talk > Databases > DB2


Thread Tools
Display Modes


Similar Threads

Thread Thread Starter Forum Replies Last Post
Query to find structure of a table Geek_Guest SQL 12 09-01-2008 10:12 PM
Table structure copying krishnaindia2007 Oracle 1 11-28-2007 02:13 AM
How to view the structure of the table Subashini.Ramasamy SQL Server 14 11-26-2007 06:58 AM
copy the Table Structure vcyogi SQL Server 3 08-04-2007 01:43 AM
Creating a table by copying another table's structure Allan Paul Oracle 12 07-12-2007 06:53 AM


All times are GMT -4. The time now is 02:05 AM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Copyright © 2008 GeekInterview.com. All Rights Reserved