Question : how can i loop through the tables in my database and do a record count for each table?

can someone tell me how i can loop through each table in my database and return a record count for each table?

thanks!

Answer : how can i loop through the tables in my database and do a record count for each table?

i got all these errors, what was the error ?
 -- I had no errors here on Nwind/Trigg..


/*
**  Cursor method to cycle through the Information Schema Tables view and get Rowcount for each table
**
** Revision History:
** ---------------------------------------------------
**  Date       Name       Description      Project
** ---------------------------------------------------
**  13/04/04   DJB        As given above     Tools
** v2 /*removing bug that was in the first post of an extra , */ and v3 limit to tables only.
*/

SET NOCOUNT ON

 
-- declare all variables!
DECLARE  @Table_Name     sysname
 

-- declare the cursor

DECLARE ISTTabs CURSOR FOR
SELECT    table_name
FROM      INFORMATION_SCHEMA.TABLES
where table_type = 'BASE TABLE'
 

OPEN ISTTabs
FETCH ISTTabs INTO @Table_Name
 

-- start the main processing loop.

WHILE @@Fetch_Status = 0
   BEGIN

   -- This is where you perform your detailed row-by-row
   -- processing.

     exec ('select count(*) as counter_val, '''+@table_name+''' as table_name
             from ['+@table_name+']')

   -- Get the next row.
   FETCH ISTTabs INTO @Table_Name
   END

CLOSE ISTTabs
DEALLOCATE ISTTabs
Random Solutions  
 
programming4us programming4us