Below is a script that I often use to rebuild indexes based on a fragmenation level, the script uses the ALTER INDEX statement to do the rebuild. A word of caution rebuilding an index will lock the table from use until the process is complete. The script first finds all the indexes that match the fragmentation clause and then loops through each index to do to the rebuild.