sql语句查询sqlserver 所有数据库表的大小

with temp AS(SELECT convert(char(8), getdate(), 112) AS date_id, tablename N'table_name', max(used_G) AS 'use_space_G', max(rows) AS row_nums, getdate() AS insert_time FROM (SELECT object_name(id) tablename, 8 * reserved / 1024 reserved, (8 * dpages / 1024.0/1024.0) used_G, 8 * (reserved - dpages) / 1024 unused, 8 * dpages / 1024 - rows / 1024 * minlen / 1024 free, rows FROM sysindexes a) AS b GROUP BY tablename) SELECT date_id as 时间, table_name as 表名, use_space_G as 大小_M, row_nums as 行数统计, insert_time as 查询时间 FROM temp ORDER BY row_nums DESC

SQL执行历史记录:

with temp AS(SELECT convert(char(8), getdate(), 112) AS date_id, tablename N'table_name', max(used_G) AS 'use_space_G', max(rows) AS row_nums, getdate() AS insert_time FROM (SELECT object_name(id) tablename, 8 * reserved / 1024 reserved, (8 * dpages / 1024.0/1024.0) used_G, 8 * (reserved - dpages) / 1024 unused, 8 * dpages / 1024 - rows / 1024 * minlen / 1024 free, rows FROM sysindexes a) AS b GROUP BY tablename) SELECT date_id as 时间, table_name as 表名, use_space_G as 大小_M, row_nums as 行数统计, insert_time as 查询时间 FROM temp ORDER BY row_nums DESC

SQL操作返回历史记录:

2023-02-26 21:03:32:634 输入:with temp AS(SELECT convert(char(8), getdate(), 112) AS date_id, tablename N'table_name', max(used_G) AS 'use_space_G', max(rows) AS row_nums, getdate() AS insert_time FROM (SELECT object_name(id) tablename, 8 * reserved / 1024 reserved, (8 * dpages / 1024.0/1024.0) used_G, 8 * (reserved - dpages) / 1024 unused, 8 * dpages / 1024 - rows / 1024 * minlen / 1024 free, rows FROM sysindexes a) AS b GROUP BY tablename) SELECT date_id as 时间, table_name as 表名, use_space_G as 大小_M, row_nums as 行数统计, insert_time as 查询时间 FROM temp ORDER BY row_nums DESC

sql语句查询sqlserver 所有数据库表的大小_第1张图片

2023-02-26 21:03:32:647 输出:查看数据库所有表的大小 : 132 张表

smartsofthelp 最好数据库应用优化软件

下载地址:

https://pan.baidu.com/s/1RzJq5rKEJWq5xGUIo7jYjw?pwd=8888

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