Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with updating statistics

Status
Not open for further replies.

Ed75

MIS
Joined
Sep 29, 2004
Messages
27
Location
US
I am using the following script to update the stats on my dataabses
Code:
DECLARE @table_name varchar(1000),@sql nvarchar(4000)

declare c1 cursor for SELECT name

FROM sysobjects

WHERE xtype = 'U'

open c1

      fetch next from c1 into @table_name

      while @@Fetch_Status = 0

        begin

       Select @sql = 'UPDATE STATISTICS '+ @table_name +' WITH FULLSCAN'

         --print @sql

         exec sp_executesql @sql

       fetch next from c1 into @table_name

        end

close c1

deallocate c1

GO

One one database I am getting an error stating that the table does not exist. The table does indeed exist and if I omit that table from my script it goes to the next line of the sysobjects table and then tells me that the next table does not exist.

Any Ideas?
Thanks,
Ed
 
obviously you need brackets around the tablename, you might have spaces or something like that

change this

Code:
SELECT name
FROM sysobjects
to this
Code:
SELECT quotename(name)
FROM sysobjects
and try again

Denis The SQL Menace
--------------------
SQL Server Code,Tips and Tricks, Performance Tuning
SQL Server Programming Hacks
 
Exact same error, good thought though
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top