Detect defects, format and refactor T-SQL code