May 27, 2008 at 10:51 pm
Is it possible to write a query to display all the tables in a database with the number of records in the same table like: (using sp_tables, etc..)
Tables count(table)
table1 125
table2 135
table3 125
May 27, 2008 at 10:57 pm
I don't have my Guru's Guide with me (I'm at home) so I'm not positive with the syntax, but search for sp_MSForEachTable. It is an undocumented stored procedure that will let you do what you want.
Something like...
EXEC sp_MSForeachtable @command = 'SELECT ?, COUNT(*) FROM ?'
-SQLBill
May 27, 2008 at 11:07 pm
You don't need a cursor (not even a hidden one, as in the sp_MSforeachTable proc), this article lists a view that can do this, and includes much more per table information as well: http://qa.sqlservercentral.com/scripts/tables/62545/
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
May 28, 2008 at 12:34 am
Thanks I got it
May 28, 2008 at 5:53 am
good luck! Let us know if you have any more questions.
[font="Times New Roman"]-- RBarryYoung[/font], [font="Times New Roman"] (302)375-0451[/font] blog: MovingSQL.com, Twitter: @RBarryYoung[font="Arial Black"]
Proactive Performance Solutions, Inc. [/font][font="Verdana"] "Performance is our middle name."[/font]
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply