|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 8:23 PM
Points: 338,
Visits: 443
|
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Tuesday, June 04, 2013 8:08 AM
Points: 94,
Visits: 212
|
|
I'm running this but I'm getting
(0 row(s) affected) Msg 102, Level 15, State 1, Line 11 Incorrect syntax near ')'.
I'm trying to track it down but it's a little complicated, and it's still running so I don't want to mess with it until it's finished. Any ideas on what could cause this?
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Friday, April 19, 2013 7:46 AM
Points: 20,
Visits: 41
|
|
Is there a way to run this against only a single database within the SQL Server? When I ran it, it ran against all 12 databases being hosted by the instance.
Thank you, Wes Crockett
|
|
|
|
|
SSC Journeyman
      
Group: General Forum Members
Last Login: Tuesday, June 04, 2013 8:08 AM
Points: 94,
Visits: 212
|
|
I pulled the following code below from the script so I could try to debug my issue. You could use it to build the statements and then just run the ones you want.
Use YOURDATABASE GO
SELECT avg_fragmentation_in_percent, CASE WHEN avg_fragmentation_in_percent BETWEEN 5 AND 30 THEN 'ALTER INDEX [' + name + '] ON ' + (SELECT TOP 1 TABLE_SCHEMA FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = OBJECT_NAME(b.[OBJECT_ID]) AND TABLE_TYPE = 'BASE TABLE') + '.[' + OBJECT_NAME(b.[OBJECT_ID]) + '] REORGANIZE ;' WHEN avg_fragmentation_in_percent > 30 THEN 'ALTER INDEX [' + name + '] ON ' + (SELECT TOP 1 TABLE_SCHEMA FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = OBJECT_NAME(b.[OBJECT_ID]) AND TABLE_TYPE = 'BASE TABLE') + '.[' + OBJECT_NAME(b.[OBJECT_ID]) + '] REBUILD WITH (FILLFACTOR = 90) ;' END AS Index_Statement FROM sys.dm_db_index_physical_stats (DB_ID(), NULL, NULL, NULL, NULL) AS a JOIN sys.indexes AS b ON a.object_id = b.object_id AND a.index_id = b.index_id WHERE avg_fragmentation_in_percent > 5 AND index_type_desc <> 'HEAP' AND page_count > 640 ORDER BY avg_fragmentation_in_percent DESC
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Tuesday, June 04, 2013 7:15 AM
Points: 44,
Visits: 74
|
|
Tim,
Executing the Stored Proc on 2008R2 gives this error....
(0 row(s) affected)
(0 row(s) affected)
(0 row(s) affected)
(0 row(s) affected)
(0 row(s) affected)
(0 row(s) affected)
(0 row(s) affected)
(0 row(s) affected) Msg 102, Level 15, State 1, Line 11 Incorrect syntax near '('.
(0 row(s) affected)
(0 row(s) affected)
(0 row(s) affected)
(0 row(s) affected)
(1 row(s) affected)
|
|
|
|
|
Old Hand
      
Group: General Forum Members
Last Login: Friday, May 10, 2013 8:23 PM
Points: 338,
Visits: 443
|
|
Hi everyone,
Take a look at the attached file, which has the SQL script in known good formatted state. I'm guessing there may have been an issue with the code formatting in the article versus what I actually have in my SQL script.
Please try the attached script and let me know if this resolves the issue.
The attached script name is ReorgRebuildIndex.txt. Of course you will need to change the extension back to a .SQL for it to run in SSMS.
Tim P.
|
|
|
|
|
SSC Rookie
      
Group: General Forum Members
Last Login: Tuesday, January 29, 2013 6:07 PM
Points: 36,
Visits: 167
|
|
Hi all,
I borrowed the guts of what Timothy Parker did and created a version that works on one database only, so there is no outer cursor loop. I also added two output parameters, a try/catch, and renamed some object to suit my conventions.
Thanks, Timothy
Jeff Roughgarden
|
|
|
|