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 > MySQL > Parameter information of table.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-12-09, 02:28
amitbora27 amitbora27 is offline
Registered User
 
Join Date: May 2009
Posts: 41
Parameter information of table.

How do I get the Parameter information of table?
I have table like

mysql> desc account;

+----------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+----------+--------------+------+-----+---------+-------+
| acct_num | int(11) | NO | PRI | NULL | |
| amount | decimal(2,0) | YES | | NULL | |
+----------+--------------+------+-----+---------+-------+

I want all the information like colname, datatype, collength, precision, scale, Nullable. I tried using the

MYSQL_FIELD *fields;
unsigned int num_fields;

pResult = mysql_store_result(MySQLDB);
num_fields= mysql_num_fields(pResult);
fields = mysql_fetch_fields(pResult);
for( i = 0; i < num_fields; i++)
{
printf("Field %u is %s\n", i, fields[i].name);
}

It is giving me output like :
Field
Type
NULL
KEY
Default

row = mysql_fetch_row(pResult);
it will give me output as :
acct_num

Which I wanted to get.

But other information not gettting like datatype, precision, scale, nullable.

If I fire a query select * from account;It will gives me What I want in fields.
But it is not good if the there are 100 table which has millions of records and I want information of each table.
Is there any other way to get only the required information?
Reply With Quote
  #2 (permalink)  
Old 06-12-09, 05:01
mike_bike_kite mike_bike_kite is offline
vaguely human
 
Join Date: Jun 2007
Location: London
Posts: 2,519
This table has what you're after :
Code:
select  *
from    information_schema.COLUMNS
where  table_schema = schema()
        and table_name = "YourTableName";
Was there really a need to post another thread asking the same info?
Reply With Quote
  #3 (permalink)  
Old 06-16-09, 01:12
amitbora27 amitbora27 is offline
Registered User
 
Join Date: May 2009
Posts: 41
Thanks you very much. I solved my problem.
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