For me, this particular code to generate a script to recreate indexes has more practical use in a replication environment. For example, the default replication setting is to exclude the non-clustered indexes. What if later on you realize some or all of the non-clustered indexes are in-fact needed on subscribers? Also generally speaking, index needs for publisher vs. subscriber databases can be vastly differently. So you may have different sets of indexes among the publisher and all subscribers. This code can be executed against pubplisher and/or suscriber databases to generate the index creation script. You can then execute the generated script the subscriber/s databases. -- If there is duplicated index with different name, it won't catch it -- If table has Statistics but don't have any index, it will generate "The object does not have any indexes." alert. Please ignroe that if so. -- Uses features available in SQL server 2005 and up SET NOCOUNT ON SET TRANSACTIO...