Hi I apologize for the question i'll ask. It could be a newbie question but it's not really part of my knowledge...I got a script (mostly found on Internet)to reindex all indexes in a database.here it is :--count records in Travail.dbo.Index_Log where Complete=0if (Select count(pkIndex_Log) as Ind_Count from Travail.dbo.Index_Log where Complete=0 and Run_Type='Indexing') = 0Begin-----START INSERT-----DECLARE @Cur_Run int SET @Cur_Run=(select isnull(max(Run_No),0) + 1 from Travail.dbo.Index_Log)DECLARE @TableName sysnameDECLARE cur_reindex CURSOR FORSELECT TABLE_NAMEFROM INFORMATION_SCHEMA.TABLESOPEN cur_reindexFETCH NEXT FROM cur_reindex INTO @TableNameWHILE @@FETCH_STATUS = 0BEGINDECLARE @IndexName sysnameDECLARE cur_reindexA CURSOR FOR SELECT i.name as index_nameFROM dbo.sysindexes iWHERE id = object_id(@TableName) and i.indid > 0 and i.indid < 255and (indexkey_property(object_id(@TableName), i.indid, 1, N'isdescending') is not null)and (i.name is not null) and dpages>0OPEN cur_reindexAFETCH NEXT FROM cur_reindexA INTO @IndexNameWHILE @@FETCH_STATUS = 0BEGINinsert into Travail.dbo.Index_Log (Complete, Table_Name, Index_Name, Run_No,Run_Type) values(0, @TableName, @IndexName, @Cur_Run, 'Indexing')FETCH NEXT FROM cur_reindexA INTO @IndexNameENDCLOSE cur_reindexADEALLOCATE cur_reindexAFETCH NEXT FROM cur_reindex INTO @TableNameENDCLOSE cur_reindexDEALLOCATE cur_reindex-----END INSERT----- End----------------------------------END Insert table values------------------DECLARE @doTableName varchar(75), @doIndexName varchar(75), @dopkIndex_Log intDECLARE cur_doindex CURSOR FORselect Table_Name, Index_Name, pkIndex_Log from Travail.dbo.Index_Log where Complete=0 and Run_Type='Indexing'OPEN cur_doindexFETCH NEXT FROM cur_doindex INTO @doTableName, @doIndexName, @dopkIndex_LogWHILE @@FETCH_STATUS = 0BEGINupdate Travail.dbo.Index_Log set Start_Date=getDate() where pkIndex_Log=@dopkIndex_LogDBCC DBREINDEX (@doTableName, @doIndexName, 0, sorted_data_reorg)update Travail.dbo.Index_Log set End_Date=getDate(), Run_Type='Indexed',Complete=1 where pkIndex_Log=@dopkIndex_LogFETCH NEXT FROM cur_doindex INTO @doTableName, @doIndexName, @dopkIndex_LogENDCLOSE cur_doindexDEALLOCATE cur_doindex
The purpose of this script is to list (and store in a table) all indexes for all tables in a DB then reindex them. My problem is that this script works only for the table owned by DBO and not for the others. It seems that the variable @tablename returns always dbo.xxxxxx...Unfortunatly I can't change the owner of the tables.SELECT i.name as index_nameFROM dbo.sysindexes iWHERE id = object_id(@TableName) and i.indid > 0 and i.indid < 255and (indexkey_property(object_id(@TableName), i.indid, 1, N'isdescending') is not null)and (i.name is not null) and dpages>0
This code don't work if the owner is not dbo.Is there some code I could add (or replace) to change that ?Thans for all inputs.Thanks