Several times my colleagues asked me about rebuilding all indices in a database. While there are several solution available, I like to use the one below. Please note that sp_MSforeachtable is undocumented but internal so we can