Set NoCount ON
declare @TableName sysname,@ColName sysname,@cmd varchar(254)
DECLARE collist CURSOR FOR
SELECT object_name(a.id)TableName,a.name ColName from syscolumns a JOIN sysobjects b on a.id=b.id WHERE b.xtype='U'
-- and object_name(a.id)=
order by 1,2
OPEN collist
FETCH NEXT FROM collist into @TableName, @ColName
WHILE @@FETCH_STATUS = 0
BEGIN
select rtrim(@TableName)+'\'+@ColName
Set @cmd='SELECT SUM(DATALENGTH('+@ColName+')) FROM '+@TableName
-- print 'Command to execute: '+@cmd
exec(@cmd)
FETCH NEXT FROM collist into @TableName, @ColName
END
CLOSE collist
DEALLOCATE collist
GO
|