SQL Cop static analysis tests
Published 03 March 2015
SQL Test includes a number of static analysis tests you can run to detect issues with your database. For a comprehensive set of over 100 advanced static code analysis rules for SQL, Redgate offers SQL Code Guard.
SQL Cop tests were originally contributed by George Mastros of Less Than Dot and are now hosted on GitHub under the stewardship of Redgate (see announcement on SQL Server Central). Issues and pull requests welcome!
Adding the SQL Cop tests
To add the tests, when you add a new database to SQL Test, make sure the Add SQL Cop static analysis tests check box is selected:
To add the tests to a database you've already added to SQL Test, in the SQL Test tab right-click the database and click Add SQL Cop Static Analysis Tests:
List of tests
The following static analysis tests are included:
- Ad hoc distributed queries
- Agent service
- Auto close
- Auto create statistics
- Auto Shrink
- Auto update statistics
- Buffer cache hit ratio
- Column collation does not match database default
- Column data types (Numeric vs. Int)
- Column name problems
- Columns of data type text/nText
- Columns with float data type
- Columns with image data type
- Compatibility level
- Database and Log files on the same disk
- Database collation
- Database mail
- Decimal size problem
- Forwarded records
- Fragmented Indexes
- Instant file Initialization
- Login language
- Max degree of parallelism
- Missing foreign key indexes
- Missing foreign keys
- Old backups
- Ole automation procedures
- Orphaned users
- Page life expectancy
- Procedures named SP_
- Procedures that call undocumented procedures
- Procedures using dynamic SQL without sp_executesql
- Procedures with @@Identity
- Procedures With SET ROWCOUNT
- Procedures without SET NOCOUNT ON
- Service account
- SMO and DMO
- Table name problems
- Tables that start with tbl
- Tables without a primary key
- Tables without any data
- UniqueIdentifier with NewId
- Unnamed constraints
- User aliases
- Varchar size problem
- Views with order by
- Wide table
- xp_cmdshell is enabled