Cursor:

 

--Declaracion

DECLARE nombre_cursor CURSOR FOR
sentencia select
OPEN nombre_cursor
FETCH NEXT FROM nombre_cursor INTO @variable
WHILE @@FETCH_STATUS<>-1 BEGIN
-- siguiente registro
FETCH NEXT FROM nombre_cursor INTO @variable
END
CLOSE nombre_cursor
DEALLOCATE nombre_cursor
-Ejemplo

Declare @name varchar(100)
Declare @Cont int
Declare @tab TABLE (tabla varchar(100), numReg int)
DECLARE Tabs CURSOR FOR
SELECT name FROM sysobjects WERE type='u' ORDER BY 1
OPEN Tabs
FETCH NEXT FROM tabs INTO @name
WHILE @@FETCH_STATUS<>-1 BEGIN
INSERT INTO @tab (tabla,numReg)
EXEC('SELECT ''' + @name+ '''' + ', COUNT(*) FROM ' + @name)
-- siguiente
FETCH NEXT FROM tabs INTO @name
END
CLOSE tabs
DEALLOCATE tabs
SELECT * FROM @tab order by numReg