sql 随笔(mysql)

1.查询用户拥有的表的表名
  select
a.table_name from information_schema.tables a;
2.查询用户拥有的某个数据库的表
  
select a.table_name from information_schema.tables a where a.table_schema = '数据库名';
3.查询用户拥有的所有表的大概记录数
  
select a.table_name,a.table_rows from information_schema.tables a where a.table_schema='数据库名';
4.查询用户拥有的所有表的详细记录数
  
useinformation_schema;

  select concat(

'select "',
table_name,
'",count(*) from ',
table_schema,'.',table_name,
' union all'
)from tables a where a.table_schema = '数据库名';
  说明:其中union all 可以将产生的sql 拼接起来不报错。相当于";".
5.随机取出数据
  select * from 表名order by RAND() limit 10;
 
 
 
posted @ 2014-04-16 09:43  mr.g.  阅读(129)  评论(0编辑  收藏  举报