Quantcast
Channel: Transact-SQL forum
Viewing all articles
Browse latest Browse all 23857

Re-Indexing - Only get performance back using management studio

$
0
0

SQL Server 2005 (SP2)

I have a nightly job that populates a table that is queried heavily everyday.  After about 4 months of no issues, suddenly the performance of the query was slowing down.  In the first 4 months I used to just delete all the rows, and then insert again without worrying about re-indexing.  Once I began experiencing the issues I have since changed to dropping the table, re-creating the table, populating and re-creating the index nightly.  But the issue is still there...   

If I go into Management Studio, and choose "Rebuild All" on the table's indexes (there is only one index) everything works fine, and the query once again performs as expected.

To avoid needing to manually go in and choose the Rebuild All everyday, I searched for T-SQL scripts to rebuild it in the nightly process.  Each of the scripts I have tried fail to make a difference and still require me to do it manually through Management Studio.  (Even though when it prompts me it says there is 0 Total Fragmentation)

Currently this is what I'm using:

DECLARE @TableName varchar(255)

DECLARE TableCursor CURSOR FOR
SELECT table_name FROM information_schema.tables
WHERE table_type = 'base table'

OPEN TableCursor

FETCH NEXT FROM TableCursor INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
DBCC DBREINDEX(@TableName,' ',90)
FETCH NEXT FROM TableCursor INTO @TableName
END

CLOSE TableCursor

DEALLOCATE TableCursor

 

Any help is appreciated.

Viewing all articles
Browse latest Browse all 23857

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>