在SQL Server和Oracle数据库中均有系统表提供这些信息,在Mysql中没有系统表,如何才能得到呢?

解决方案 »

  1.   

    show create table tbname
      

  2.   

    show columns from tbname
      

  3.   

    在C的环境下执行show create table books;的过程如下:
    //main.c
    #include<stdio.h>
    #include <winsock2.h>
    #include <mysql.h>
    #pragma comment (lib, "libmysql.lib")int main()
    {
    //declare structure and variables
    MYSQL mysql;
    MYSQL_RES *result;
    MYSQL_ROW row;
    int i;
    int j;
        //initialize MYSQL structure
    mysql_init(&mysql); //connect to database
    if(!(mysql_real_connect(&mysql,"localhost","root","12142022","BookDB",0,NULL,0)))
    {
    fprintf(stderr,"Error in connection: %s\n",mysql_error(&mysql));
    exit(1);
    } //execute query
    mysql_query(&mysql,"set names gbk");
    if(mysql_query(&mysql,"show create table books")!=0)
    {
    fprintf(stderr,"Error in query: %s\n",mysql_error(&mysql));
    exit(1);
    } //get result set
    if(!(result=mysql_store_result(&mysql)))
    {
    fprintf(stderr,"Error in reading result set : %s\n",mysql_error(&mysql));
    exit(2);
    }
    else
    {
    //if valid result set
    //iterate over rows
    //for each row,iterate over fields and print contents
    int long numRecords=mysql_num_rows(result);
    int numFields=mysql_num_fields(result);
    //process result set
    /* while((row=mysql_fetch_row(result)))
    {
    fprintf(stdout,"%s - %s\n",row[0],row[1]);
    }
    */
    //clean up
    for(i=0;i<numRecords;i++)
    {
    row=mysql_fetch_row(result);
    for(j=0;j<numFields;j++)
    {
    fprintf(stdout,"%s",row[j]);
    (j!=(numFields-1)) ? printf(", ") : printf("\n");
    }
    }
    mysql_free_result(result);
    }
    mysql_close(&mysql);}输出如下:
    books, CREATE TABLE `books` (
      `id` varchar(8) NOT NULL default '',
      `name` varchar(24) NOT NULL default '',
      `title` varchar(96) NOT NULL default '',
      `price` float NOT NULL default '0',
      `yr` int(4) unsigned NOT NULL default '0',
      `description` varchar(30) NOT NULL default '',
      `saleAmount` int(10) unsigned NOT NULL default '0',
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=gbk
    Press any key to continue我想其他的也应该差不多吧,就是用query来执行相应的命令
    希望对你有所帮助
      

  4.   

    To:XqYuan(),mathematician(数学家)比如,我要在delphi中实现这样一个程序:
    在连接好MySQL数据库后,将选定的表的结构显示出来,如何实现大家提到的desc tablename;
    只能在MySQL的命令行显示出来,我想知道的是在我得应用程序显示出来而不是告诉我的用户自己找个MySQL的客户端,自己去敲desc tablename;命令去查看表
      

  5.   

    你用dephi不能使用这个sql语句吗?奇怪.....这不就是普通的SQL语句吗??又不是管理命令