How To Get Table Row Counts Quickly And Painlessly
Use sysindexes\DMVs insead of select count(*) to retreive table row counts
2011-01-28 (first published: 2009-09-02)
57,380 reads
---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