sqlserver查询表空间大小,使用大小,数据条数
查询表空间大小,使用大小,总记录数
DROP TABLE # temp CREATE TABLE # temp ( name VARCHAR (100), rows INT , reserved varchar (20), data varchar (20), index_size varchar (20), unused varchar (20) ) DECLARE @tablename VARCHAR (100) DECLARE @sql VARCHAR (500) DECLARE @str VARCHAR (100) DECLARE tablecursor CURSOR FOR SELECT name FROM sysobjects WHERE xtype = 'u' OPEN tablecursor FETCH NEXT FROM tablecursor INTO @tablename WHILE @@fetch_status = 0 BEGIN SET @str = @tablename SET @sql = 'insert into #temp EXEC sp_spaceused ' + @tablename EXEC (@sql) FETCH NEXT FROM tablecursor INTO @tablename END CLOSE tablecursor DEALLOCATE tablecursor SELECT * FROM # temp |
查询表记录数:
DROP TABLE # temp CREATE TABLE # temp ( Recordcount INT , tableName VARCHAR (100) ) DECLARE @tablename VARCHAR (100) DECLARE @sql VARCHAR (500) DECLARE @str VARCHAR (100) DECLARE tablecursor CURSOR FOR SELECT name FROM sysobjects WHERE xtype = 'u' OPEN tablecursor FETCH NEXT FROM tablecursor INTO @tablename WHILE @@fetch_status = 0 BEGIN SET @str = @tablename SET @sql = 'insert into #temp(recordcount,tablename) select count(*),' + '' '' + @tablename + '' '' + ' from ' + @tablename EXEC (@sql) FETCH NEXT FROM tablecursor INTO @tablename END CLOSE tablecursor DEALLOCATE tablecursor SELECT * FROM # temp ORDER BY Recordcount |
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 手把手教你在本地部署DeepSeek R1,搭建web-ui ,建议收藏!
· 新年开篇:在本地部署DeepSeek大模型实现联网增强的AI应用
· Janus Pro:DeepSeek 开源革新,多模态 AI 的未来
· 互联网不景气了那就玩玩嵌入式吧,用纯.NET开发并制作一个智能桌面机器人(三):用.NET IoT库
· 【非技术】说说2024年我都干了些啥