使用sql语句获取SQL server库里所有表的表名,注释,行数

select * from (SELECT  

  t.name,schema_id,

    SCHEMA_NAME(schema_id)+'.'+t.name AS 表名,  

    c.value AS 注释  

FROM   

    sys.tables AS t  

LEFT JOIN   

    sys.extended_properties AS c

         ON c.major_id = t.object_id AND c.minor_id = 0 AND c.name = 'MS_Description'

) ss

left join ( SELECT OBJECT_NAME(p.object_id) AS [表名], SUM(p.rows) AS [行数]

        FROM sys.partitions p WHERE p.index_id < 2

            AND OBJECT_NAME(p.object_id) IS NOT NULL

GROUP BY p.object_id) aa

        on ss.name = aa.[表名]

      order by SCHEMA_NAME(schema_id)+'.'+ name

你可能感兴趣的:(sql,数据库)