August 25, 2006 at 10:54 am
Hi,
I found this script to display all tables and row count for each, but it only returns tables owned by dbo. How can I modify it to show other schemas as well in the database?
SELECT[TableName] = so.name, [Table id]=so.id,[RowCount]
= MAX(si.rows)
FROM
sysobjects so, sysindexes si
WHEREso
.xtype = 'U'
and si.id = OBJECT_ID(so.name)
GROUPBY
so.name,so.id
ORDERBY
2DESC
Thanks!!
Isabelle
Thanks!
Bea Isabelle
August 25, 2006 at 12:07 pm
hmm, maybe this...
SELECT [TableName] = so.name, [Table id]=so.id,[RowCount]= MAX(si.rows)
FROM
sysobjects so, sysindexes si
WHEREso
.xtype = 'U'
and si.id = so.id
GROUP BY so.name,so.id ORDERBY
so.idDESC
Because I don't see anything that filters the owner...August 25, 2006 at 12:10 pm
Thank you. That worked. What does the object_id(so.name) do that it causes other schemas not to show up?
Isabelle
Thanks!
Bea Isabelle
August 25, 2006 at 12:32 pm
Couldn't find anything out about that... but that was the only thing I could see that may have a chance of screwing something up.
August 25, 2006 at 12:46 pm
I couldn't either. When I did a comparison for the values in sysobjects and sysindexes for my database, I saw that for the table owned by dbo there was a value in OBJECT_ID(so.name), but in all the tables owned by a different schema, they were NULL and that's why they are not getting picked up. I just don't understand what OBJECT_ID is doing or where that value is coming from.
Thanks for your help.
Isabelle
Thanks!
Bea Isabelle
August 25, 2006 at 1:02 pm
I'm certain it queries sysobjects but I never saw the query so I'd just be speculating at this point... But as long a syour query works now .
Viewing 6 posts - 1 through 5 (of 5 total)
You must be logged in to reply to this topic. Login to reply