如何用SQL語句查詢表名和行數(shù)

字號:

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
    ...
    如果你需要在你的數(shù)據庫里的所有表上做這個查詢,考試#大提示可以從INFORMATION_SCHEMA.TABLES視圖生成表清單:
    select table_name
    from information_schema.tables
    where table_schema = 'mydatabase'
    然后你可以利用這個查詢的結果集和一個文本編輯器生成第一個查詢。