Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sp_MSforeachtable

Author  Topic 

rmg1
Constraint Violating Yak Guru

256 Posts

Posted - 2013-03-14 : 08:39:51
Hi all

I'm trying to sort out stats and indexes on our server and I'm running a test on 3 tables to start with (three of our biggest).
I've got the stats bit sorted, but I can't get the code to rebuild the indexes on the 3 specific tables.
This is the code I'm using:-

exec sp_updatestats
exec sp_MSforeachtable '
if in (''FACT_iApplicationStat'',''FACT_iAgentBySkillsetStat'',''FACT_iAgentPerformanceStat'')
begin
ALTER INDEX ALL ON REBUILD
end

'

I'm getting the following error:-
Msg 207, Level 16, State 1, Line 2
Invalid column name '[dbo].[FACT_iApplicationStatSummary]'.
when it starts the index rebuild.

Can anyone see where I'm going wrong?
   

- Advertisement -