Try ApexSQL Refactor
ApexSQL Refactor is a free SSMS and VS add-in for formatting SQL statements using almost 200 formatting options and 11 code repositories. It expands wildcards, qualifies object names, renames SQL database objects and parameters without breaking dependencies, encapsulates code as a stored procedure, scalar function, table function and view, adds surrogate keys and much more
Disclaimer: I work for ApexSQL as a support engineer
source share