关键字:DBA 查询 数据库 脚本
本文中介绍的参考脚本用于查询当前数据库中所有表格的记录条数,
并将结果存入TableInfo表中,不会删除以备用户再做处理与分析。最后请各位读者删除此表。
脚本示例:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[TableSpace]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[TableSpace]
go
create table TableSpace
(
TableName varchar(20),
RowsCount char(11),
Reserved varchar(18),
Data varchar(18),
Index_size varchar(18),
Unused varchar(18)
)
go
declare @sql varchar(500)
declare @TableName varchar(20)
declare Cursor1 Cursor
for
select name from sysobjects where xtype='U'
open Cursor1
fetch next from Cursor1 into @TableName
while @@fetch_status = 0
begin
set @sql = 'insert into TableSpace '
set @sql = @sql + ' exec sp_spaceused '''+ @TableName + ''' '