I'm running an SQL 2005 database for WhatsUp Gold (network monitoring software), and the indexes are highly fragmented. The WUG tool for defragmenting indices is worthless, it assumes if the query to find fragmentation times out then there's no problems.
WUG support was kind enough to provide a query I can paste into SQL Server Management Studio to see the fragmentation, but doesn't have same to just defrag all the indices.
That query is:
SELECT OBJECT_NAME(OBJECT_ID), index_id,index_type_desc,index_level, avg_fragmentation_in_percent,avg_page_space_used_in_percent,page_count FROM sys.dm_db_index_physical_stats (DB_ID(N'Whatsup.dbo'), NULL, NULL, NULL , 'SAMPLED') ORDER BY page_count DESC
I've Googled, but here's the thing: I'm a SysAdmin, I'm a NetAdmin, I've dabbled in programming, but I am so not a DBA and that's not a goal of mine. I don't even know what most of the stuff I've found means. I found what looked right, but I guess it's for T-SQL which is... different? Maybe? I have no clue.
The only useful thing I found was how to get into the tables (I think... that's what their folder says they are), right-click on the Indexes folder and Reorganize/Rebuild... and that Rebuild takes that database (or just table?) offline until it's done, but Reorg doesn't.
I don't care how "expensive" an operation is, because you know what's an expensive operation? Opening a folder, right-clicking on the Index, hitting Reorganize, waiting forever, hitting enter, waiting forever, and then doing it all over again for 240+ of these folders. Having my monitoring fail because database reads/writes time out is also expensive. The only thing running on this Windows box is SQL Server and the WUG server that it's there for (and of course the web server for WUG's interface). There's no problem with taking the DB offline.
The tables all seem to start with "dbo." like "dbo.StatisticalPing" so it LOOKS like it should just be...
ALTER INDEX dbo.* REORGANIZE (or REBUILD)
... but of course, SQL complains "Incorrect syntax near '.'." so it must not be that simple.
But it can't be THAT much more complex, can it? I just don't know what I don't know to not know how to do. o.o