Results 1 to 3 of 3
  1. #1
    Join Date
    May 2009
    Posts
    41

    Unanswered: 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?

  2. #2
    Join Date
    Jun 2007
    Location
    London
    Posts
    2,527
    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?

  3. #3
    Join Date
    May 2009
    Posts
    41
    Thanks you very much. I solved my problem.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •