辅导:如何用SQL语句查询表名和行数
来源:优易学  2011-11-11 13:06:19   【优易学:中国教育考试门户网】   资料下载   IT书店
 Rudy Limeback:
  是的,这相当简单。
  select 'Customers' as tablename
  , count(*) as row_count
  from Customers
  union all
  select 'Orders' as tablename
  , count(*) as row_count
  from Orders
  union all
  select 'Products' as tablename
  , count(*) as row_count
  from Products
  union all
  ...
  如果你需要在你的数据库里的所有表上做这个查询,青年人网站提示可以从INFORMATION_SCHEMA.TABLES视图生成表清单:
  select table_name
  from information_schema.tables
  where table_schema = 'mydatabase'
  然后你可以利用这个查询的结果集和一个文本编辑器生成第一个查询。

责任编辑:小草

文章搜索:
 相关文章
热点资讯
热门课程培训