>Thank you, Martina. I will run your code on my SSMS first, before attempting it on the customer SQL Server.
>Two follow-up questions, please.
>1. Should - as far as you know - the defragmentation of indexes (running your code above or another way) be done by a DBA?
>2. Do you think it is a good idea to include the above code in the application (VFP 9) feature? That is, so that the end user can run it when they feel the data is slow?
My perception is that if you feel the performance is slow than some work has to be done to resolve the problem. You can use WA_Statistics to obtain basic information on missing indexes for exemple. Then, if you obtain metrics that certain requests are slow, probably based on some complex queries which contain a lot of fields in the where clause and a lot of included fields, then, as mentioned, you may build compound indexes. Please, note that any change in the query design needs the compound index to be adjusted. There is a limit of a certain number of fields which can be part of it.
I really wouldn't give that option to the user. This is something, if you should ever use that route, which is to allow someone to execute such a procedure, then it should be done by an administrator, off hours.