I have a mssql database, we'll call it: mssqlDB01. I've been tasked with performing defragmentation on all of the tables. This database has a few hundred tables and each table has a range of 1 to 15 indexes per table.
Google led me to discover a practice to defrag all indexes per table, but I can't figure out how to do it on all tables.
ALTER INDEX ALL ON TABLENAME REBUILD;
what i'm looking for is
ALTER INDEX ALL ON * REBUILD;
but it complains
Msg 102, Level 15, State 1, Line 2
Incorrect syntax near '*'.`
below lets me find all tables in my DB
SELECT * FROM information_schema.tables WHERE TABLE_TYPE='BASE TABLE'
can I somehow push this into the command?
ALTER INDEX ALL ON (SELECT * FROM information_schema.tables WHERE TABLE_TYPE='BASE TABLE'; ) REBUILD;