首页 > 数据库技术 > 详细

Mysql操作集锦

时间:2014-09-10 09:31:30      阅读:263      评论:0      收藏:0      [点我收藏+]

mysql安装成功后可以看到已经存在mysql、information_schema和test这个几个数据库,information_schema库中有一个名为COLUMNS的表,这个表中记录了数据库中所有表的字段信息。知道这个表后,获取任意表的字段就只需要一条select语句即可。

例如: select COLUMN_NAME from information_schema.COLUMNS where table_name = ‘your_table_name‘;上述的做法有一点问题,如果多个数据库中存在你想要查询的表名,那么查询的结果会包括全部的字段信息。

通过DESC information_schema.COLUMNS可以看到该表中列名为TABLE_SCHEMA是记录数据库名,因此下面的写法更为严格:select COLUMN_NAME from information_schema.COLUMNS where table_name = ‘your_table_name‘ and table_schema = ‘your_db_name‘;

 

Mysql操作集锦

原文:http://www.cnblogs.com/xuezhaojing/p/3963738.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!