My random rumblings

Something of everything and nothing at all

Count the number of rows in tables

declare @t table(id int primary key identity(1, 1), sql nvarchar(512), count int)
insert into @t(sql) select 'select @cOut = count(*) from [' + name + ']' from sys.tables
declare @i int = (select max(id) from @t)
while @i > 0
begin
 declare @s nvarchar(512) = (select sql from @t where id = @i)
 declare @c int
 exec sp_executeSQL @s, N'@cOut int output', @cOut = @c output
 update @t set count = @c where id = @i
 set @i = @i - 1
end
select * from @t
Loading