August 26, 2002 at 10:33 am
What would be the best way to get the number of rows in a table from a SQL script? Is there a sp for this or DMO statement?
Thanks!
August 26, 2002 at 10:39 am
Here is a script that returns record counts for every table in every database on your server. From this you should get some idea how to do what you desire.
http://www.geocities.com/sqlserverexamples/#dmscript1
-------------------------
Greg Larsen, DBA
If you looking for SQL Server Examples check out my website at http://www.geocities.com/sqlserverexamples
Gregory A. Larsen, MVP
August 26, 2002 at 10:41 am
exec sp_spaceused 'MYTABLE'
You could also use SELECT COUNT(*) FROM MYTABLE, but that would be very slow if you don't have a no-NULLs nonclustered indexed column on the table. I'd use sp_spaceused.
- Troy King
- Troy King
August 26, 2002 at 10:59 am
Try this:
EXEC sp_MSforeachtable "select '?', count(*) from ?"
Be great!
Mike
Be great!
Michael
August 26, 2002 at 11:15 am
Thanks all for the rapid response. You guys are great!
Jonathan
August 26, 2002 at 11:15 am
If you want to put the results into a table:
CREATD TABLE testt(
tab varchar(125),
cnt int)
GO
INSERT INTO testt
EXEC sp_MSforeachtable "select '?', count(*) from ?"
GO
Be great!
Mike
Be great!
Michael
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply