September 29, 2009 at 6:59 am
When I execute the following query (to list all tables in a database) for any of my SQL server databases, the result set contains 6 rows (see below). What am I doing wrong? Thanks!
SELECT
[TableName] = so.name,
[RowCount] = MAX(si.rows)
FROM
sysobjects so,
sysindexes si
WHERE
so.xtype = 'U'
AND
si.id = OBJECT_ID(so.name)
GROUP BY
so.name
ORDER BY
1 asc
TableNameRowCount
MSreplication_options3
spt_fallback_db0
spt_fallback_dev0
spt_fallback_usg0
spt_monitor1
spt_values2506
September 29, 2009 at 7:40 am
That is because you are running your script against master database, but not against your database.
In the beginng of your script you have to use
USE [YourDB_name]
GO
There is more simple way to get the list of all tables in any database::-)
USE [YourDB_name]
GO
SELECT * FROM sys.Tables
ORDER BY [name]
GO
September 29, 2009 at 7:45 am
That works - Thanks!!!
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply