Reindexing in MSSQL Express

  1. On the Windows Server on which the MSSQL Express Server is installed, create a new task in the Windows Task Scheduler

  2. Set the schedule to Daily (e.g. 4 a.m.) and select a service user who has the rights to run programs

  3. Create a new action in the Actions tab and add Program/Script and Argument:

    Program/ScriptC:\Windows\SysWOW64\cmd.exe

    Add arguments/c "C:\Scripts\reindex.cmd"

  4. Create a new Scripts folder in the directory under C:\

  5. Download the following files from this link and add them to the Scripts folder:

    • reindex.cmd

    • Reindex.sql

  6. Open the file reindex.cmd with a text editor and adjust the following line:

    osql -Usa -Ppasswordsa -WserverSql\SQLExpress -i C:\Scripts\Reindex.sql >> %logfile%

    Enter the password of the user SA and the name of the SQL server.

  7. Execute the task in the Windows task scheduler. This creates the Reindex.log file in the C:\Scripts directory