Reply to thread

After inserting or deleting a big amount of datas in a SQL Server Express database (like a channel scan, ...), the statistics are not fill.

In consequence, the database optimizer doesnt know the row number of each table and cant do his job :(


Unfortunatly with this SQL Server version you cannot schedule a maintenance plan to do that.


At least playing that query after some big changes in your database will speed up your queries. (very good for mini EPG)

The query update statistics and rebuild all indexes for all tables

[code]

USE MpTvDbRC1 -- < put your database name here

SET NOCOUNT ON

GO

DECLARE updatestats CURSOR FOR

SELECT table_name FROM information_schema.tables

    where TABLE_TYPE = 'BASE TABLE'

OPEN updatestats

DECLARE @tablename NVARCHAR(128)

DECLARE @Statement NVARCHAR(300)

FETCH NEXT FROM updatestats INTO @tablename

WHILE (@@FETCH_STATUS = 0)

BEGIN

   PRINT N'ALTER INDEX ALL ON ' + @tablename + ' REBUILD'

   SET @Statement = 'ALTER INDEX ALL ON ' + @tablename + ' REBUILD'

   EXEC sp_executesql @Statement

   PRINT N'UPDATE STATISTICS ' + @tablename

   SET @Statement = 'UPDATE STATISTICS '  + @tablename + '  WITH FULLSCAN'

   EXEC sp_executesql @Statement

   FETCH NEXT FROM updatestats INTO @tablename

END

CLOSE updatestats

DEALLOCATE updatestats

GO

SET NOCOUNT OFF

GO

[/code]


Top Bottom