Technical Article

Count all records the tables

,

This script will return a count of all the records from the tables that exist in a database

---Objetivo:Contar registros de tu base de datos 
---Fecha:03/04/2014
---Autor:Andrés Noé Michaca Trujillo

set nocount on
create table #tablas 
(
nombre varchar(80),
registros INT
)
declare
@table varchar(80),
@CadenaSQL varchar(200)

declare tablecurs cursor for
select '['+ltrim(rtrim(sq.name))+'].['+ltrim(rtrim(obj.name))+']' from sys.objects obj
inner join sys.schemas sq on
obj.schema_id =sq.schema_id where obj.type = 'U' and obj.name <>'sysdiagrams'
order by sq.name,obj.name 
open tablecurs
fetch tablecurs into @table
WHILE @@FETCH_STATUS = 0
Begin
   Select @CadenaSQL = 'select '''+ @table +''', count(*) from '+ @table 
   insert into #tablas
   exec(@CadenaSQL)
   fetch tablecurs into @table
end
deallocate tablecurs
go

select * from #tablas
GO
drop table #tablas
GO

Rate

2.29 (7)

You rated this post out of 5. Change rating

Share

Share

Rate

2.29 (7)

You rated this post out of 5. Change rating