mysql 语句

1 清除mysql 表中的数据 

a, delete from ~;

b,truncate table ~;  //不保存日志

 

2,删除表

drop table ~;

 

3,数据库中表的数量及遍历

 表的数量就是下面的tables_num

char  szSqlText[300]="";
sprintf_s(szSqlText, 300, "select count(*) FROM information_schema.tables WHERE TABLE_SCHEMA='new_schema'");
if (mysql_query(sock, szSqlText))
 {
        std::cout << "something wrong in the select * for table numbers : " << mysql_error(sock) << std::endl;
        getchar();
        exit;
  }
 res = mysql_store_result(sock);
 row = mysql_fetch_row(res);
 int tables_num = atoi(row[0]);
 

表的遍历:

 将上述sql 语句改为 show tables即可,row得到的是下一个table的名称

4,显示表中某一行的值

select * from ~ limit 3,1 ; //从第三行开始的下一行开始,取1行

SELECT * FROM table LIMIT 5,10; //检索记录行6-15 

 

posted @ 2016-03-09 21:51  Daringoo  阅读(120)  评论(0编辑  收藏  举报