Microsoft
Software
Hardware
Network
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
Resubmitting with correct file attached!: How to Hyperlink Column of UPS Tracking Numbers in Excel to UPS Webpage
How to seperate parts of a line using FOR and FINDSTR
SSIS: Insert New, Update existing -- how?
bypass key in msaccess
Subtotaling Group Calculated Fields
Microsoft, Access, 2007, Call sub without return
Display image
Using a geometry type check constrint in sql sever 2008
Internal LAN to External Ping
Microsoft, Access, 2000 How to Calculate an aproximation of the Distance between two zip codes using a query to Google Maps