I am trying to atomate getting the count of rows in each user table in a given database. I tried the following, but got an error saying the table variable needs to be declared. ?? I assume from this that a variable can not be put in the 'from' clause. Is there another way to do this?
DECLARE @TableName varchar(80)
DECLARE TableInfo CURSOR
FOR
SELECT [Name]
FROM sys.tables
OPEN TableInfo
FETCH NEXT FROM TableInfo INTO @TableName
WHILE @@fetch_status = 0
BEGIN
Select @TableName, count(*) From @TableName
FETCH NEXT FROM TableInfo INTO @TableName
END
CLOSE TableInfo
DEALLOCATE TableInfo
Thank You
Rollin Burr
Politicians and diapers have one thing in common. They should both be changed regularly, and for the same reason.