sql 随笔(mysql)

本文介绍了五种实用的SQL查询技巧,包括如何查询用户拥有的表名、特定数据库下的所有表名及记录数,并提供了随机抽取数据的方法。这些技巧对于进行数据库管理和数据查询非常有用。
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;
 
 
 

转载于:https://www.cnblogs.com/mrgong/p/3667935.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值