Hi guys
I found this script on the net to reindex and defrag my databases... doesn’t seem to work ... I am not a programmer so any help would be appreciated. Also is there a way to rebuild them or does this do that to?
/*
Defrag or re-index all indecies
*/
DECLARE @TableName sysname
DECLARE @IndexName VARCHAR(100)
DECLARE @indid int
DECLARE cur_tblfetch CURSOR FOR
SELECT name from sysobjects where xtype='U'
OPEN cur_tblfetch
FETCH NEXT FROM cur_tblfetch INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE cur_indfetch CURSOR FOR
SELECT indid,name FROM sysindexes WHERE id = OBJECT_ID (@TableName) and keycnt > 0
OPEN cur_indfetch
FETCH NEXT FROM cur_indfetch INTO @indid,@IndexName
WHILE @@FETCH_STATUS = 0
BEGIN
print 'Maintenancing ' + (@TableName) + '.' + (@IndexName)
--IF @indid <> 255 DBCC INDEXDEFRAG (0, @TableName, @indid)
IF @indid <> 255 DBCC DBREINDEX (@TableName, @IndexName)
FETCH NEXT FROM cur_indfetch INTO @indid,@IndexName
END
CLOSE cur_indfetch
DEALLOCATE cur_indfetch
FETCH NEXT FROM cur_tblfetch INTO @TableName
END
CLOSE cur_tblfetch
DEALLOCATE cur_tblfetch
I found this script on the net to reindex and defrag my databases... doesn’t seem to work ... I am not a programmer so any help would be appreciated. Also is there a way to rebuild them or does this do that to?
/*
Defrag or re-index all indecies
*/
DECLARE @TableName sysname
DECLARE @IndexName VARCHAR(100)
DECLARE @indid int
DECLARE cur_tblfetch CURSOR FOR
SELECT name from sysobjects where xtype='U'
OPEN cur_tblfetch
FETCH NEXT FROM cur_tblfetch INTO @TableName
WHILE @@FETCH_STATUS = 0
BEGIN
DECLARE cur_indfetch CURSOR FOR
SELECT indid,name FROM sysindexes WHERE id = OBJECT_ID (@TableName) and keycnt > 0
OPEN cur_indfetch
FETCH NEXT FROM cur_indfetch INTO @indid,@IndexName
WHILE @@FETCH_STATUS = 0
BEGIN
print 'Maintenancing ' + (@TableName) + '.' + (@IndexName)
--IF @indid <> 255 DBCC INDEXDEFRAG (0, @TableName, @indid)
IF @indid <> 255 DBCC DBREINDEX (@TableName, @IndexName)
FETCH NEXT FROM cur_indfetch INTO @indid,@IndexName
END
CLOSE cur_indfetch
DEALLOCATE cur_indfetch
FETCH NEXT FROM cur_tblfetch INTO @TableName
END
CLOSE cur_tblfetch
DEALLOCATE cur_tblfetch