Counting records in a database after bcpgreenspun.com : LUSENET : SQL Server Database Administration : One Thread
I need to import data into a database weekly with bcp, and would like to count the records after each bcp.
Then I want to e-mail the resulting counter to myself. I have e-mail working in SQL Server 6.5.
I can't find a command to count the records in a database without looking at each record, and this database has 3 million records and growing.
-- Anonymous, March 11, 1999
If you want the total number of rows for a table query the sysindexes table, this relies on regular 'update statistics' being run. The table lists all indexes of a table - you only need to look at those that have an indid of 0 or 1, eg;
select rows from sysindexes where id = object_id('authors') and indid <= 1
select rows from sysindexes where id = object_id('sales') and indid <= 1
-- Anonymous, March 12, 1999
If you are wanting to know the total row count then you can perform the following:
exec sp_spaceused tablename
-- Anonymous, December 02, 1999